更改ggplot中点的颜色填充和形状
问题描述:
我想更改ggplot中点的形状和颜色填充,这是我的部分工作代码,颜色图例仍然是黑色。更改ggplot中点的颜色填充和形状
ID<-rep(c("KO", "WT"), each=4)
O<-rep(c("HP", "NN"), each=2, times=2)
Methionine<-rep(c("- Methionine", "+ Methionine"), each=2, times=2)
mean.1<-sample(50:100, 8)
se.1<-runif(8, min=1, max=3)
mydata<-data.frame(ID, O, Methionine, mean.1, se.1)
ggplot(mydata, aes(x=O, y=mean.1, ymax=max(mean.1), shape=Methionine, fill=ID)) +
geom_errorbar(aes(ymin=mean.1-se.1, ymax=mean.1+se.1), size=1,colour="black", width=.15) +
geom_point(size = 10) +
scale_shape_manual(labels=c("+ Methionine", "- Methionine"),
values = c(21,22))+
scale_fill_manual(name=bquote(bold(paste(alpha, " "))), values = cols)
答
你需要告诉ggplot使用形状= 21图例,以便它使用的是注重填充规范点,即
scale_fill_manual(name=bquote(bold(paste(alpha, " "))),
values = cols,
guide=guide_legend(override.aes=list(shape=21))
完整的示例:
cols <- c("red","blue")
set.seed(101)
library(ggplot2)
mydata <- data.frame(ID=rep(c("KO", "WT"), each=4),
O=rep(c("HP", "NN"), each=2, times=2),
Methionine=rep(c("- Methionine", "+ Methionine"), each=2, times=2),
mean.1=sample(50:100, 8),
se.1=runif(8, min=1, max=3))
gg0 <- ggplot(mydata,
aes(x=O, y=mean.1, ymax=max(mean.1), shape=Methionine, fill=ID)) +
geom_errorbar(aes(ymin=mean.1-se.1, ymax=mean.1+se.1),
size=1,colour="black", width=.15) +
geom_point(size = 10)+
scale_shape_manual(labels=c("+ Methionine", "- Methionine"),
values = c(21,22))
gg0 +
scale_fill_manual(name=bquote(bold(paste(alpha, " "))),
values = cols,
guide=guide_legend(override.aes=list(shape=21))
我指出它在ggplot函数的第一行 – Al14
是真的我没有看到Methione is shape – Nate
'scale_color_manual'不起作用 – Al14