假设我有以下
y <- rnorm(10)
b <- as.factor(sample(1:4,10,replace=T))
qplot(1:10, y, shape=b)
如何更改使用的形状ggplot2
?
ggplot 方法是scale_shape_manual
在参数中使用并提供所需的形状values
:
qplot(1:10, y, shape=b) + scale_shape_manual(values = c(0, 5, 6, 15))
形状与通常的 0-25 索引相同:http: //yusung.blogspot.com/2008/11/plot-symbols-in-r.html
为了补充哈兰的回答,这里是可用形状的参考 - 从左下角的 0 开始,然后向上阅读(10y + x):
df <- data.frame(x=c(0:129))
ggplot(df, aes(x=x%%10, y=floor(x/10), shape=factor(x), colour=x, size=10)) +
geom_point() +
scale_shape_manual(values=df$x) + theme(legend.position='none') +
scale_x_continuous(breaks=0:10) + scale_y_continuous(breaks=0:12) +
scale_colour_hue() + scale_colour_gradientn(colours=rainbow(3))
> y <- rnorm(10)
> b <- as.factor(sample(1:4,10,replace=T))
> qplot(1:10, y, shape=b)
> qplot(1:10, y, pch=letters[1:10], cex=6)
你是这个意思吗?我想你可以使用任何 R 的绘图字符......
不过,这可能不是一种非常“ggplot”的方式,但手册页确实显示“您可以像使用 'plot' 函数一样使用它。”。:-)