使 scale_colour_manual 在 R 中的 ggplot2 上为我的多因素条形图工作的问题
Problems with making scale_colour_manual work for my multi-factor bargraph on ggplot2 in R
我正在尝试为我的条形图制作一个手动色标,使用 plyr 来汇总数据并使用 ggplot2 来呈现图表。
数据有两个变量:
- 区域(显示在 X 轴上)
- 基因型(由填充显示)
我已经设法做到这一点,但是,我还没有找到个性化颜色的方法 - 它只是给了我两种随机分配的颜色。
有人可以帮我弄清楚我在这里遗漏了什么吗?
我已经包含了我的代码和下图的图像。该图基本上具有我想要的外观,只是我无法个性化颜色。
ggplotdata <- summarySE(data, measurevar="Density", groupvars=c("Genotype", "Region"))
ggplotdata
#Plot the data
ggplotdata$Genotype <- factor(ggplotdata$Genotype, c("WT","KO"))
Mygraph <-ggplot(ggplotdata, aes(x=Region, y=Density, fill=Genotype)) +
geom_bar(position=position_dodge(), stat="identity",
colour="black",
size=.2) +
geom_errorbar(aes(ymin=Density-se, ymax=Density+se),
width=.2,
position=position_dodge(.9)) +
xlab(NULL) +
ylab("Density (cells/mm2)") +
scale_colour_manual(name=NULL,
breaks=c("KO", "WT"),
labels=c("KO", "WT"),
values=c("#FFFFFF", "#3366FF")) +
ggtitle("X") +
scale_y_continuous(breaks=0:17*500) +
theme_minimal()
Mygraph
这里的答案是用scale_fill_manual代替,谢谢@dc37
我正在尝试为我的条形图制作一个手动色标,使用 plyr 来汇总数据并使用 ggplot2 来呈现图表。
数据有两个变量:
- 区域(显示在 X 轴上)
- 基因型(由填充显示)
我已经设法做到这一点,但是,我还没有找到个性化颜色的方法 - 它只是给了我两种随机分配的颜色。
有人可以帮我弄清楚我在这里遗漏了什么吗?
我已经包含了我的代码和下图的图像。该图基本上具有我想要的外观,只是我无法个性化颜色。
ggplotdata <- summarySE(data, measurevar="Density", groupvars=c("Genotype", "Region"))
ggplotdata
#Plot the data
ggplotdata$Genotype <- factor(ggplotdata$Genotype, c("WT","KO"))
Mygraph <-ggplot(ggplotdata, aes(x=Region, y=Density, fill=Genotype)) +
geom_bar(position=position_dodge(), stat="identity",
colour="black",
size=.2) +
geom_errorbar(aes(ymin=Density-se, ymax=Density+se),
width=.2,
position=position_dodge(.9)) +
xlab(NULL) +
ylab("Density (cells/mm2)") +
scale_colour_manual(name=NULL,
breaks=c("KO", "WT"),
labels=c("KO", "WT"),
values=c("#FFFFFF", "#3366FF")) +
ggtitle("X") +
scale_y_continuous(breaks=0:17*500) +
theme_minimal()
Mygraph
这里的答案是用scale_fill_manual代替,谢谢@dc37