Turning off some legends in a ggplot

Suppose I have a ggplot with more than one legend. mov <- subset(movies, length != “”) (p0 <- ggplot(mov, aes(year, rating, colour = length, shape = mpaa)) + geom_point() ) I can turn off the display of all the legends like this: (p1 <- p0 + theme(legend.position = “none”)) Passing show_guide = FALSE to geom_point … Read more

How to change facet labels?

I have used the following ggplot command: ggplot(survey, aes(x = age)) + stat_bin(aes(n = nrow(h3), y = ..count.. / n), binwidth = 10) + scale_y_continuous(formatter = “percent”, breaks = c(0, 0.1, 0.2)) + facet_grid(hospital ~ .) + theme(panel.background = theme_blank()) to produce I’d like to change the facet labels, however, to something shorter (like Hosp … Read more

Remove legend ggplot 2.2

I’m trying to keep the legend of one layer (smooth) and remove the legend of the other (point). I have tried shutting off the legends with guides(colour = FALSE) and geom_point(aes(color = vs), show.legend = FALSE). Edit: As this question and its answers are popular, a reproducible example seems in order: library(ggplot2) ggplot(data = mtcars, … Read more

Center Plot title in ggplot2

This simple code (and all my scripts from this morning) has started giving me an off center title in ggplot2: Ubuntu version: 16.04 R studio version: Version 0.99.896 R version: 3.3.2 GGPLOT2 version: 2.2.0 I have freshly installed the above this morning to try and fix this… dat <- data.frame( time = factor(c(“Lunch”,”Dinner”), levels=c(“Lunch”,”Dinner”)), total_bill … Read more

Plotting two variables as lines using ggplot2 on the same graph

A very newbish question, but say I have data like this: test_data <- data.frame( var0 = 100 + c(0, cumsum(runif(49, -20, 20))), var1 = 150 + c(0, cumsum(runif(49, -10, 10))), date = seq(as.Date(“2002-01-01″), by=”1 month”, length.out=100) ) How can I plot both time series var0 and var1 on the same graph, with date on the … Read more