I have this ggplot2
script:
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"))
Which produces this plot:
Now, I'd like to fill the density curves with their corresponding colours (at, say, 25% alpha). Isn't fill = variable
the usual way to do this?
Your example is needlessly complex if you're just concerned about filling the area under the line.
Here's a simple example of filling the area under the lines of your data using geom_area
and your sample data.
ggplot(data=dataM, aes(x= x, y=value, fill = variable)) +
geom_area(alpha = .75, position="identity")
which returns