也许这是一个非常基本的问题,但我是一个初学者。
我使用这个命令来获得一个barplot:
ggplot(data=melt, aes(x=variable, y=value, fill=value)) +
geom_bar(width=.8, stat="identity") +
xlab("Samples") + ylab("Expression") + ggtitle("Gapdh") +
theme(plot.title=element_text(face="bold", size=12)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1, size=10)) +
theme(axis.text.y = element_text(size=10))我想要更改原图的颜色,但保留颜色的梯度取决于值列。我试过了,但是我失去了梯度:
ggplot(data=melt, aes(x=variable, y=value, fill=value)) +
geom_bar(width=.8, stat="identity", fill="red") +
xlab("Samples") + ylab("Expression") + ggtitle("Gapdh") +
theme(plot.title=element_text(face="bold", size=12)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1, size=10)) +
theme(axis.text.y = element_text(size=10))数据很简单,只有两列(变量-值):
variable value
1 nu73 13576.49
2 nu73t 10891.88
3 nu81 12673.33
4 nu81t 12159.91
5 nu83 12570.82
6 nu83t 11828.04提前谢谢你们
发布于 2014-11-14 17:15:14
您想要调整缩放,特别是填充颜色的连续比例,因此函数scale_fill_continuous()。
ggplot(data = melt, aes(x = variable, y = value, fill = value)) +
geom_bar(width = .8, stat = "identity") +
labs(x = "Samples", y = "Expression", title = "Gapdh") +
theme(plot.title = element_text(face = "bold", size = 12),
axis.text.x = element_text(angle = 45, hjust = 1, size = 10),
axis.text.y = element_text(size = 10)) +
scale_fill_continuous(low = "firebrick4", high = "firebrick1")(我稍微修改了绘图代码:您可以使用多个参数调用theme一次,我发现labs比一组单独的标记调用更好。)
另一种选择是使用RColorBrewer包中的调色板(将其合并到ggplot2中)。scale_fill_brewer()标度如果用于离散色尺度,可以用scale_fill_distiller()将它们“提取”成连续刻度。例如
scale_fill_distiller(type = "seq", palette = "Reds")要查看所有可用的刻度,请运行RColorBrewer::display.brewer.all()。
https://stackoverflow.com/questions/26935195
复制相似问题