[R] ggplot2 fill problem in colour shading

Troels Ring tr|ng @end|ng |rom gvdnet@dk
Sun Aug 11 18:13:37 CEST 2019

Dear friends - I have 2  problems with ggplot2

Here is the code for illustration


x <- seq(1,10,length=10000)

y <- x^2

fill <- rep(0,length(x))

fill[(5<x)&(x<7.5)] <- "red"

ddf <- data.frame(x,y,fill)

ggplot(data=ddf,aes(x=x,y=y)) + geom_area(aes(fill=fill)) + geom_line()


First the embarrassing one: I would really like no fill except from x from 5
to 7.5 or transparency so the background is still visible. Have tried NULL
and NA with no effect.

The other thing is that it appears that above the blue area some of the
other color spills true - reddish on my system.


Windows 10 

R version 3.6.1 


All best wishes

Troels Ring

Aalborg, Denmark

	[[alternative HTML version deleted]]

More information about the R-help mailing list