I have a data frame that looks like this:
df <- data.frame(
group = c(rep("A", 4),rep("B", 4), rep("C", 4)),
word = c(rep(c("first", "first", "second", "second"), 3)),
emphasis = c(rep(c("normal", "emphatic"), 6)),
percentage = c(.175, .07, .13, .04, .60, .43, .21, .28, .63, .63, .40, .29))
I want to create a line graph that looks pretty much like this:
library(ggplot2)
p <- ggplot(df, aes(x = group, y = percentage, group = emphasis, col = emphasis))
p + geom_line() + facet_wrap(~ word)+ scale_y_continuous(label = percent) + geom_point(size=4, shape=21, colour="black")
I can't quite figure out how to get the y scale to 100%, since I don't have a data point that reaches that high. I thought scale_y_continuous(limits = c(0, 100)
would do the trick, but it doesn't. I imagine it must be easy, but I can't find any examples of how to do it.
This will give you the full range from 0% to 100% with percent labels:
library(scales) # For the percent_format() function
scale_y_continuous(labels = percent_format(), limits=c(0,1))
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