में भरने मैं एक छात्र द्वारा पूछा गया कि क्या यह संभव था एक साजिश आर का उपयोग कर नीचे एक के समान बनाना geom_polygon को कस्टम छवि जोड़ना:ggplot
इस से this paper....
सामान इस तरह की है मेरी विशेषता नहीं है, लेकिन निम्नलिखित कोड का उपयोग करके मैं 95% सीआई इलिप्स बनाने और geom_polygon()
के साथ साजिश करने में सक्षम था। मैंने rphylopic
पैकेज का उपयोग करके फ़िलोपिक लाइब्रेरी से प्राप्त छवियों वाली छवियों को भर दिया।
#example data/ellipses
set.seed(101)
n <- 1000
x1 <- rnorm(n, mean=2)
y1 <- 1.75 + 0.4*x1 + rnorm(n)
df <- data.frame(x=x1, y=y1, group="A")
x2 <- rnorm(n, mean=8)
y2 <- 0.7*x2 + 2 + rnorm(n)
df <- rbind(df, data.frame(x=x2, y=y2, group="B"))
x3 <- rnorm(n, mean=6)
y3 <- x3 - 5 - rnorm(n)
df <- rbind(df, data.frame(x=x3, y=y3, group="C"))
#calculating ellipses
library(ellipse)
df_ell <- data.frame()
for(g in levels(df$group)){
df_ell <- rbind(df_ell, cbind(as.data.frame(with(df[df$group==g,], ellipse(cor(x, y),
scale=c(sd(x),sd(y)),
centre=c(mean(x),mean(y))))),group=g))
}
#drawing
library(ggplot2)
p <- ggplot(data=df, aes(x=x, y=y,colour=group)) +
#geom_point(size=1.5, alpha=.6) +
geom_polygon(data=df_ell, aes(x=x, y=y,colour=group, fill=group), alpha=0.1, size=1, linetype=1)
### get center points of ellipses
library(dplyr)
ell_center <- df_ell %>% group_by(group) %>% summarise(x=mean(x), y=mean(y))
### animal images
library(rphylopic)
lion <- get_image("e2015ba3-4f7e-4950-9bde-005e8678d77b", size = "512")[[1]]
mouse <- get_image("6b2b98f6-f879-445f-9ac2-2c2563157025", size="512")[[1]]
bug <- get_image("136edfe2-2731-4acd-9a05-907262dd1311", size="512")[[1]]
### overlay images on center points
p + add_phylopic(lion, alpha=0.9, x=ell_center[[1,2]], y=ell_center[[1,3]], ysize=2, color="firebrick1") +
add_phylopic(mouse, alpha=1, x=ell_center[[2,2]], y=ell_center[[2,3]], ysize=2, color="darkgreen") +
add_phylopic(bug, alpha=0.9, x=ell_center[[3,2]], y=ell_center[[3,3]], ysize=2, color="mediumblue") +
theme_bw()
निम्नलिखित में से कौन देता है:
यह ठीक है, लेकिन क्या मैं वास्तव में क्या करना चाहते हैं geom_polygon की 'भरने' कमांड के लिए सीधे एक छवि जोड़ना है। क्या यह संभव है ?
मुझे लगता है आधिकारिक उत्तर "यह संभव नहीं है" ([हैडली का जवाब] (http://stackoverflow.com/a/2901210/1900149))। हालांकि, @baptiste [यहां] द्वारा एक और हालिया जवाब है (http://stackoverflow.com/questions/26110160/how-to-apply-cross-hatching-to-a-polygon-using-the-grid- graphical- प्रणाली) जो सहायक साबित हो सकती है। – tonytonov
यह वह नहीं है जो आप पूछ रहे हैं, लेकिन "सही नौकरी के लिए सही उपकरण" की भावना में: मैं इसके पीछे डेटा के साथ आर में अंतर्निहित ग्राफ बनाउंगा। इसके बाद मैं फ़ोटोशॉप का उपयोग करता हूं, या यह मुफ्त, खुले स्रोत के समतुल्य समतुल्य [जीआईएमपी] (http://www.gimp.org/) का उपयोग करेगा। फिर विभिन्न परतें बनाएं और अंडाकार आकार के माध्यम से अपनी पारदर्शिता समायोजित करें। –