我绘制四维数据集。 除了x轴和y轴,我要代表第三和由不同的宽度和高度的矩形的第四尺寸。 我能做到这一点与ggplot
? 谢谢。
Answer 1:
这是一种方法:
dd <- data.frame(x = (x <- 1:10),
y = x + rnorm(10), width = runif(10,1,2), height = runif(10,1,2))
ggplot(data = dd) +
geom_rect(aes(xmax = x + width/2, xmin = x - width/2,
ymax = y + height/2, ymin = y - height/2),
alpha =0.2, color = rgb(0,114,178, maxColorValue=256),
fill = rgb(0,114,178, maxColorValue=256)) +
coord_fixed() +
theme_bw()
Answer 2:
你可以尝试这样的事情。 我用
-
geom_point
具有形状= 0到模拟矩形 -
geom_rect
创建ractangle点为中心
我在这里的数据(这将是更好地提供一些数据)
d=data.frame(x=seq(1,10),
y=seq(1,10),
width=rep(c(0.1,0.5),each =5),
height=rep(c(0.8,0.9,0.4,0.6,0.7),each =2))
ggplot(data = d) +
geom_rect(aes(xmax = x + width, xmin = x-width,
ymax = y+height, ymin = y - height),
color = "black", fill = NA) +
geom_point(mapping=aes(x=x, y=y,size=height/width),
color='red',shape=0)+
theme_bw()
文章来源: How to use different shapes for every point in ggplot