I have created the plot below with these commands:
ggplot(long.data, aes(owner,value)) + stat_summary(fun.y=mean,geom="bar",
fill=c("deepskyblue","deepskyblue4")) +
stat_summary(fun.data=mean_cl_normal,geom="errorbar",position=
position_dodge(width=.90),width=.1) +
labs(x="",y="") + facet_grid(IV~experiment+type,scales="free_y") +
theme(strip.text.y = element_text(colour = 'red4'))
If I want to change the text color (and possibly also the background color) for only the upper x facet (in this case 'Implicit' and 'Explicit' levels), how can I do that? Is it possible? I have not read nothing about that in the ggplot2 documentation.
EDIT: I'm sorry for the confusion. My aim is to change the text and background color of one of the upper strips, not the color of the facet.
You want to change the attributes of the strip
element, not the facet. Try something like the code below. Note that this is a minimal example based on fake data made up at random, as you did not provide your own data for us to work with. You'll have to adapt the code to your needs.
require(reshape)
require(ggplot2)
require(scales)
# fake data
mydf <- data.frame(val1 = runif(10, 0, 1), val2 = runif(10, 0, 1))
mydf
# reshape to long format
long.data <- melt(mydf)
long.data$facetvar <- "implicit"
long.data$facetvar[seq(1, 19, 2)] <- "explicit"
long.data
# plot
ggplot(long.data, aes(y = value, x = variable)) +
geom_bar(position = 'dodge', stat = "identity") +
facet_wrap (~ facetvar) +
theme(strip.background = element_rect(fill = alpha('green', 0.3))) +
theme(strip.text.x = element_text(colour = 'blue', size = 10))
This produces a plot like this:
Please note that you have waited quite a while (by the standards of the R community on Stack Overflow) for an answer because your question wasn't clear and because you didn't provide fully reproducible code and data that we can copy and paste into our own R installations. If you had done that, somebody far more knowledgeable than myself would have answered this question within an hour. Please see this very useful post for tips on how to ask your next question.
I get a warning
... but this seems a good starting point for a more elegant solution:
ggplot(mtcars) + geom_rect(data = subset(mtcars, cyl == 4), aes(fill = cyl),xmin = -inf,xmax = Inf, ymin = -Inf,ymax = Inf, alpha = 0.05) +
geom_point(aes(mpg, wt)) + facet_grid(. ~ cyl)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With