用颜色填充密度图
Filling density plot with colours
我有这个 ggplot2
脚本:
require(reshape2)
library(ggplot2)
library(RColorBrewer)
library(extrafont)
font_import(pattern = 'Arch')
font_import(pattern = 'Akk')
fileName = paste("/ex_spectra.csv", sep = "") # data: https://www.dropbox.com/s/gs1hwv3xjnlhb7z/ex_spectra.csv?dl=0
mydata = read.csv(fileName,sep=",", header=TRUE, check.names=FALSE)
dataM = melt(mydata,c("x"))
my_palette = c(brewer.pal(5, "Set1")[c(1,2,3,4,5)])
ggplot(data=dataM, aes(x= x, y=value, colour=variable, fill = variable, size = variable)) +
geom_line(alpha = .75) +
scale_colour_manual(breaks=c("A", "B", "C", "D", "E"), values=my_palette) +
scale_size_manual(breaks=c("A", "B", "C", "D", "E"), values=c(0.7,0.7,0.7,0.7,0.7)) +
theme(plot.background = element_blank(), panel.grid.minor = element_blank(), #panel.grid.major = element_blank(),
axis.line = element_blank(),
legend.key = element_blank(), legend.title = element_blank()) +
scale_y_continuous("y", expand=c(0,0)) +
scale_x_continuous("x", expand=c(0,0)) +
theme(axis.title.x = element_text(vjust=-0.3, face="bold", size=12, colour = "grey50", family="AkkuratPro-Regular")) +
theme(axis.title.y = element_text(vjust=1.5, face="bold", size=12, colour = "grey50", family="AkkuratPro-Regular")) +
theme(legend.position = "right", axis.ticks = element_blank(),
axis.text.x = element_text(size = 9, angle = 0, vjust = 0.25 , hjust = 1, colour = "grey50", family="AkkuratLightPro-Regular")
,axis.text.y = element_text(size = 9, angle = 0, hjust = 1, colour = "grey50", family="AkkuratLightPro-Regular"))
产生这个情节的是:
现在,我想用相应的颜色(比如 25% alpha)填充密度曲线。 fill = variable
不是通常的做法吗?
如果您只关心填充线条下方的区域,那么您的示例就不必要地复杂了。
这是一个使用 geom_area
和示例数据填充数据线下方区域的简单示例。
ggplot(data=dataM, aes(x= x, y=value, fill = variable)) +
geom_area(alpha = .75, position="identity")
哪个returns
我有这个 ggplot2
脚本:
require(reshape2)
library(ggplot2)
library(RColorBrewer)
library(extrafont)
font_import(pattern = 'Arch')
font_import(pattern = 'Akk')
fileName = paste("/ex_spectra.csv", sep = "") # data: https://www.dropbox.com/s/gs1hwv3xjnlhb7z/ex_spectra.csv?dl=0
mydata = read.csv(fileName,sep=",", header=TRUE, check.names=FALSE)
dataM = melt(mydata,c("x"))
my_palette = c(brewer.pal(5, "Set1")[c(1,2,3,4,5)])
ggplot(data=dataM, aes(x= x, y=value, colour=variable, fill = variable, size = variable)) +
geom_line(alpha = .75) +
scale_colour_manual(breaks=c("A", "B", "C", "D", "E"), values=my_palette) +
scale_size_manual(breaks=c("A", "B", "C", "D", "E"), values=c(0.7,0.7,0.7,0.7,0.7)) +
theme(plot.background = element_blank(), panel.grid.minor = element_blank(), #panel.grid.major = element_blank(),
axis.line = element_blank(),
legend.key = element_blank(), legend.title = element_blank()) +
scale_y_continuous("y", expand=c(0,0)) +
scale_x_continuous("x", expand=c(0,0)) +
theme(axis.title.x = element_text(vjust=-0.3, face="bold", size=12, colour = "grey50", family="AkkuratPro-Regular")) +
theme(axis.title.y = element_text(vjust=1.5, face="bold", size=12, colour = "grey50", family="AkkuratPro-Regular")) +
theme(legend.position = "right", axis.ticks = element_blank(),
axis.text.x = element_text(size = 9, angle = 0, vjust = 0.25 , hjust = 1, colour = "grey50", family="AkkuratLightPro-Regular")
,axis.text.y = element_text(size = 9, angle = 0, hjust = 1, colour = "grey50", family="AkkuratLightPro-Regular"))
产生这个情节的是:
现在,我想用相应的颜色(比如 25% alpha)填充密度曲线。 fill = variable
不是通常的做法吗?
如果您只关心填充线条下方的区域,那么您的示例就不必要地复杂了。
这是一个使用 geom_area
和示例数据填充数据线下方区域的简单示例。
ggplot(data=dataM, aes(x= x, y=value, fill = variable)) +
geom_area(alpha = .75, position="identity")
哪个returns