I ran into an issue with RStudio's preview release v1.2.1047 (whose Python support is fantastic, btw! thanks!) that I wanted to get in as feedback. reprex
doesn't seem to be working (I'll like @jennybryan know on GitHub), but here is what is needed to reproduce this behavior:
library(ggplot2)
# create data frame
popPlot <- data.frame(
year = c(1900, 1910, 1920, 1930, 1940, 1950, 1960, 1970, 1980, 1990, 2000, 2010, 2016),
pop = c(575238, 687029, 772897, 821960, 816048, 856796, 750026, 622236, 452801, 396685,
348189, 319294, 311404)
)
If I create my plot with no breaks in the scale_y_continuous
or labs
arguments like I have below, the plot builds just fine:
# plot data
ggplot(data = popPlot, aes(x = year, y = pop)) +
geom_line(color = "#349E8B", size = 2) +
scale_x_continuous(breaks = c(1900, 1920, 1940, 1960, 1980, 2000, 2016)) +
scale_y_continuous(breaks = c(300000, 400000, 500000, 600000, 700000, 800000, 900000), labels = c(300, 400, 500, 600, 700, 800, 900), limits = c(300000, 900000)) +
labs(title = "St. Louis's Population, 1900-2016", x = "Year", y = "Population (thousands)")
However, I like my ggplot
calls to be a bit more readable, so I normally build them this way:
# plot data
ggplot(data = popPlot, aes(x = year, y = pop)) +
geom_line(color = "#349E8B", size = 2) +
scale_x_continuous(breaks = c(1900, 1920, 1940, 1960, 1980, 2000, 2016)) +
scale_y_continuous(
breaks = c(300000, 400000, 500000, 600000, 700000, 800000, 900000),
labels = c(300, 400, 500, 600, 700, 800, 900),
limits = c(300000, 900000)) +
labs(
title = "St. Louis's Population, 1900-2016",
x = "Year",
y = "Population (thousands)")
That code, however, results in a number of errors:
> breaks = c(300000, 400000, 500000, 600000, 700000, 800000, 900000),
Error: unexpected ',' in " breaks = c(300000, 400000, 500000, 600000, 700000, 800000, 900000),"
> labels = c(300, 400, 500, 600, 700, 800, 900),
Error: unexpected ',' in " labels = c(300, 400, 500, 600, 700, 800, 900),"
> limits = c(300000, 900000)) +
Error: unexpected ')' in " limits = c(300000, 900000))"
> labs(
+
I checked this code in R
outside of RStudio and it works just fine. It was also working in the last stable version of RStudio.