How to set limits for axes in ggplot2 R plots?

I plot the following: library(ggplot2) carrots <- data.frame(length = rnorm(500000, 10000, 10000)) cukes <- data.frame(length = rnorm(50000, 10000, 20000)) carrots$veg <- ‘carrot’ cukes$veg <- ‘cuke’ vegLengths <- rbind(carrots, cukes) ggplot(vegLengths, aes(length, fill = veg)) + geom_density(alpha = 0.2) Now say, I only want to plot the region between x=-5000 to 5000, instead of the entire … Read more

How to change legend title in ggplot

I have the following plot like below. It was created with this command: library(ggplot2) df <- data.frame(cond = factor(rep(c(“A”, “B”), each = 200)), rating = c(rnorm(200), rnorm(200, mean=.8))) ggplot(df, aes(x=rating, fill=cond)) + geom_density(alpha = .3) + xlab(“NEW RATING TITLE”) + ylab(“NEW DENSITY TITLE”) Now, I want to modify the legend title from cond into NEW … Read more