ग्रिड ग्राफिक्स के साथ
को हटाने के द्वारा साजिश सौंदर्यशास्त्र संशोधित करना चाहते हैं जाएगा
library(grid)
ellipse <- function (x = 0, y = 0, a=1, b=1,
angle = pi/3, n=300)
{
cc <- exp(seq(0, n) * (0+2i) * pi/n)
R <- matrix(c(cos(angle), sin(angle),
-sin(angle), cos(angle)), ncol=2, byrow=T)
res <- cbind(x=a*Re(cc), y=b*Im(cc)) %*% R
data.frame(x=res[,1]+x,y=res[,2]+y)
}
pyramidGrob <- function(labels = c("ellipse", paste("cell",1:7)),
slope=5,
width=1, height=1,
fills=c(rgb(0, 113, 193, max=256),
rgb(163, 163, 223, max=256),
rgb(209, 210, 240, max=256),
rgb(217, 217, 217, max=256)), ...,
draw=FALSE){
a <- 0.4
b <- 0.14
ye <- 3/4 + b*sin(acos((3/4/slope-0.5)/a))
e <- ellipse(0.5, ye, a=a, b=b,angle=0)
g1 <- polygonGrob(e$x, e$y, gp=gpar(fill=fills[1]))
x1 <- c(0, 0.5, 0.5, 1/4/slope, 0)
y1 <- c(0, 0, 1/4, 1/4, 0)
x2 <- c(1/4/slope, 0.5, 0.5, 1/2/slope, 1/4/slope)
y2 <- y1 + 1/4
x3 <- c(1/2/slope, 0.5, 0.5, 3/4/slope, 1/2/slope)
y3 <- y2 + 1/4
x4 <- c(0.5 - 3/4/slope, 0.5 + 3/4/slope,
0.5 + 3/4/slope, 0.5 - 3/4/slope,
0.5 - 3/4/slope)
y4 <- y3
d <- data.frame(x = c(x1,1-x1,x2,1-x2,x3,1-x3,x4),
y = c(y1,y1,y2,y2,y3,y3,y4),
id = rep(seq(1,7), each=5))
g2 <- with(d, polygonGrob(x, y, id,
gp=gpar(fill=fills[c(rep(2:4,each=2),4)])))
x5 <- c(0.5, 0.25, 0.25, 0.25, 0.75, 0.75, 0.75, 0.5)
y5 <- c(3/4+1/8, 1/8, 1/2 - 1/8, 1/2 + 1/8,
1/8, 1/2 - 1/8, 1/2 + 1/8, 1/2 + 1/8)
g3 <- textGrob(labels, x5,y5, vjust=1)
g <- gTree(children=gList(g1,g2,g3), ...,
vp=viewport(width=width,height=height))
if(draw) grid.draw(g)
invisible(g)
}
grid.newpage()
## library(gridExtra)
source("http://gridextra.googlecode.com/svn/trunk/R/arrange.r")
grid.arrange(pyramidGrob(height=0.4),
pyramidGrob(),
pyramidGrob(width=0.5),ncol=2)
इसके अलावा, ग्रिड व्यूपोर्ट का उपयोग उसी पृष्ठ पर विभिन्न ऑब्जेक्ट्स रखने के लिए किया जा सकता है। उदाहरण के लिए,
library(gridExtra)
grid.arrange(tableGrob(head(iris)[,1:3]),
pyramidGrob(), qplot(1:10,1:10),
lattice::xyplot(1:10~1:10), ncol=2,
main = "arrangement of Grid elements")
तुम सच में आर के साथ ऐसा करना चाहते हैं? जो मुझे समझ में नहीं आता वह अंतर्निहित प्रेरणा है ...इस तरह की चीजें आसानी से वेक्टर ग्राफिक्स प्रोग्राम के साथ बनाई जा सकती हैं, और आपको केवल आर पर जोर देना चाहिए यदि आप इसे प्रोग्रामेटिक रूप से और/या दिखाने के लिए तैयार हैं। =) अन्यथा, इस तरह के दृष्टिकोण सिर्फ कोई समझ नहीं लेते हैं ... – aL3xa
शेष स्कोरकार्ड आर के साथ पूरी तरह से (और स्वचालित रूप से) किया जाता है और यह वास्तव में आखिरी टुकड़ा है। इसलिए, व्यक्तिगत रूप से इन ग्राफिक्स को बनाने के लिए आर छोड़ना संभव है, लेकिन दर्दनाक होगा। इसलिए, मैं पहले क्यों पूछता हूं - दूसरा काम कुचलना। –
अंडाकार के लिए, यह मदद कर सकता है: http://stackoverflow.com/questions/2397097/how-can-a-data-ellipse-be-superimposed-on-a-ggplot2-scatterplot और https://github.com /JoFrhwld/FAAV/blob/master/r/stat-ellipse.R –