我想根据v2
按形状绘制点,并根据v3
填充,其中填充是实心的或空心的。所以圆形和三角形是实心的或空心的。
我不想达到我在下面显示的内容:1个4级因子。我想要2个因素,每个2个等级。
library(ggplot2)
ex <- data.frame(v1=c("item1", "item2", "item3", "item4"),
v2=c("circle", "circle", "triangle", "triangle"),
v3=c("filled", "hollow", "filled", "hollow"),
v4=c(1, 2, 3, 4))
ex$v5 <- paste0(ex$v2, ex$v3)
ggplot(ex, aes(x=v1, y=v4, shape=factor(v5))) +
geom_point(size=3) +
scale_shape_manual(values=c(19, 1, 17, 2),
name = "shapes!",
labels = c("circlefilled", "circlehollow",
"trianglefilled", "trianglehollow"))
答案 0 :(得分:0)
ggplot(ex, aes(x=v1, y=v4, shape=factor(v2), fill=factor(v3))) +
geom_point(size=3) +
scale_shape_manual(values=c(21, 24),
name = "shapes!")+
scale_fill_manual(values=c("black", NA))
(由于某种原因,填充图例似乎错了,我想知道它是否是最近的错误。)
或者,使用alpha
ggplot(ex, aes(x=v1, y=v4, shape=factor(v2))) +
geom_point(size=3) +
geom_point(size=3, aes(alpha=factor(v3)), fill="black") +
scale_shape_manual(values=c(21, 24),
name = "shapes!"))+
scale_alpha_manual(values=c(1, 0))
但传说也有点不理想(以不同的方式)。