Christopher's answer is perfectly correct. Let me add that ggplot
also seems to accept lists:
plot <- ggplot(data, aes(x, y)) +
list(
geom_point(),
aes(alpha=0.3,color=scale),
scale_color_gradient(high="red"),
NULL
)
Unfortunately, unlike Python where you can write [1, 2, 3, ]
, the construct list(1, 2, 3, )
produces an error in R. This is the reason for the final NULL
, which is happily ignored by ggplot2
.
Another possible workaround is to write
plot <- ggplot(data, aes(x, y)) +
geom_point() +
#aes(alpha=0.3,color=scale) +
#scale_color_gradient(high="red") +
list()
The final list()
is supposed to stay in place to cancel the effects of the last +
sign; it is a no-op otherwise.