plot with filled area and line plot

Hi,

I have data with 2 columns (NCORE and PILS).
For the PILS, I want to make a line plot with a filled area. For the NCORE, I want to make only a line plot.

Wavelength	NCORE	PILS
300	         NaN	92.29
350	        18.79	48.20
365	        18.02	39.85
405	        16.24	23.03
430	        15.29	16.94
445	        14.78	13.52
500	        13.15	6.618
532	        12.36	5.262
550	        11.96	1.360

For doing this, I am using code:


wavelength %>%
  slice(1:n()) %>% 
  melt(id.vars=1:1) %>% 
  ggplot(aes(Wavelength, value, fill=variable)) + geom_area(alpha=0.6)+
  geom_line(size=0.2) + 
  xlab(bquote('Wavelength (nm)'))   +
  ylab(bquote('BrC - Absorbance')) +
  labs(title = "29th June")+
  ylim(0,100)+
  theme(legend.text=element_text(size=12)) + 
  theme(legend.title=element_blank()) +
  theme(legend.position = c(0.8, 0.8)) +
  theme(axis.title = element_text(face="plain",size=14,color="black"),
        axis.text=element_text(size=12,face="plain", color="black"),
        plot.title = element_text(size=15)) +
  scale_color_brewer(palette="Set1")+
  ylab(bquote('Abs ('*Mm^-1*')')) 

from this code, I am getting plot like

But, in this plot, I want to remove the filled area from NCORE (the red one). I only want a line plot for the NCORE column and on the front side. Right now in this plot, the red points (line) are behind the green that's why all the red points are in shadow. I want to make all the red points more clear.

Please let me know how to do it.

Thanks

Hi,

If you would not like the geom_area to include the NCORE variable, you can specify this in the function
(see where I have added the data argument, and then filtered to exclude the NCORE variable):

wavelength <- tibble(Wavelength = c(300, 350, 365, 405, 430, 445, 500, 532, 550),
                     NCORE = c(NA, 18.79, 18.02, 16.24, 15.29, 14.78, 13.15, 12.36, 11.96),
                     PILS = c(92.29, 48.20, 39.85, 23.03, 16.95, 13.52, 6.618, 5.262, 1.360)) |>
  dplyr::slice(1:n()) |> 
  reshape2::melt(id.vars = 1:1) 

ggplot(data = wavelength, 
       mapping = aes(x = Wavelength, y = value)) + 
  geom_area(data = wavelength |> filter(variable != 'NCORE'), alpha = 0.6, fill = 'blue')+
  geom_point(mapping = aes(col = variable))+ 
  geom_line(mapping = aes(col = variable))+ 
  scale_color_manual(values = c('red', 'blue'))

...which produces:
image

1 Like

Thanks for your suggestion.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.