2017-02-07 9 views
7

मैं शुरू में इस पृष्ठभूमि बनाने के लिए geom_raster और geom_tile उपयोग करने की कोशिश, लेकिन इसके बजाय एक छवि का उपयोग कर का सहारा के रूप में मैंने सोचा कि यह आसान होगा का उपयोग करने पर अंक अस्तर एक कठिन समय बीत रहा है।एक छवि ggplot2

हालांकि, मैं पूरी पृष्ठभूमि को लेने के लिए छवि नहीं प्राप्त कर सकता हूं ताकि अंक शीर्ष पर सही हो। पृष्ठभूमि छवि यहाँ है: http://imgur.com/a/eZGAP

यह इस तरह दिखना चाहिए: enter image description here

लेकिन यह इस तरह बाहर आ रहा है:

structure(list(Industry.Group = c("Defense/Military", "Energy", "Financial Services", "Healthcare", "Manufacturing", "Public Sector (non-defense)/Not For Profit", "Retail", "Services", "Technology", "Telecommunications", "Transportation" ), ciq_tech = c(55.9, 53.7111111111111, 60.743661971831, 45.0620689655172, 42.1529411764706, 52.2444444444444, 40.8, 52.3263157894737, 50.9222222222222, 59.5111111111111, 39.6666666666667), Industry.Group = c("Defense/Military", "Energy", "Financial Services", "Healthcare", "Manufacturing", "Public Sector (non-defense)/Not For Profit", "Retail", "Services", "Technology", "Telecommunications", "Transportation"), ciq_org = c(39.6666666666667, 48.7413636363636, 48.0868442622951, 42.2482222222222, 39.0128260869565, 38.482, 39.7786956521739, 41.7248387096774, 47.8644262295082, 49.6739285714286, 41.4825)), .Names = c("Industry.Group", "ciq_tech", "Industry.Group", "ciq_org"), row.names = c(NA, -11L), class = "data.frame")

: enter image description here

यहाँ डेटा की एक dput है

मैंने कोशिश की है और xmin समायोजित कर रहा है, xmax और ymin और ymax चर:

library(png) 
library(grid) 
library(ggplot2) 
img <- readPNG("grid.png") 
g <- rasterGrob(img, interpolate=TRUE) 

ggplot(both, aes(x = ciq_org, y = ciq_tech)) + 
    theme_bw() + annotation_custom(g, xmin=31, xmax=57, ymin=38, ymax=61) + geom_point() 

साथ ही:

ggplot(both, aes(x = ciq_org, y = ciq_tech)) + 
    theme_bw() + annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + geom_point() 

मैं भी geom_raster का उपयोग कर के लिए खुला बजाय अगर यह तय वर्गों और रंग के साथ पृष्ठभूमि पुन: बनाने के लिए आसान हो जाएगा हूँ ngatively ggplot2 में।

उत्तर

4

आप इस कोशिश कर सकते हैं:

ggplot(both, aes(x = ciq_org, y = ciq_tech)) + 
    theme_bw() + annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + 
    geom_point(size=5, col='steelblue') + 
    xlim(c(31, 57)) + 
    ylim(c(38,61)) + 
    theme_void() 

enter image description here

+1

वाह, गंभीरता से? बहुत बहुत धन्यवाद, मुझे लगा कि मैं इसे खत्म कर रहा था! – tcash21

3

यहाँ एक वैकल्पिक समाधान मैं पर काम कर रहा था:

img <- png::readPNG("KRWa02Q.png", info = TRUE) 
dimensions <- attr(img, "info")$dim 

p <- ggplot(both, aes(x = ciq_org, y = ciq_tech)) + 
     annotation_raster(img, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf, interpolate = TRUE) + 
     geom_point(size = 3) + 
     theme(axis.ticks = element_blank(), axis.line = element_blank(), axis.title = element_blank(), axis.text = element_blank(), 
       panel.grid = element_blank(), panel.border = element_blank(), panel.background = element_rect(fill = NA), 
       aspect.ratio = dimensions[1]/dimensions[2], 
       plot.margin = margin(0, 0, 0, 0, "in")) + 
     scale_x_continuous(expand = c(0.15, 0.15)) + 
     scale_y_continuous(expand = c(0.15, 0.15)) 

ggsave("tc.png", p, width = dimensions[1]/72, height = dimensions[2]/72, units = "in", dpi = 72) 

Draft of image for tcash21

+0

बहुत बढ़िया वैकल्पिक समाधान! – tcash21