ggtitle

How to change the chart title dynamically in R?

元气小坏坏 提交于 2021-02-05 06:48:26
问题 Here is an example using mtcars to split by a variable into separate plots. What I created is a scatter plot of vs and mpg by splitting the data set by cyl . First an empty list is created. Then I used lapply to loop through the values of cyl (4,6,8) and then filter the data by that value. After that I plotted the scatter plot for the subset and saved it to the empty list. library(dplyr) library(ggplot2) gglist <- list() gglist <- lapply(c(4,6,8), function(x){ ggplot(filter(mtcars, cyl == x))

accessing data of the plot within ggtitle

北城以北 提交于 2020-12-29 04:03:46
问题 I am wondering if it is somehow possible to access the columns of the provided data within a ggplot2 graph for the title. So something like that: ggplot(mpg %>% filter(manufacturer == 'audi'), aes(x = hwy, y = displ, label = model)) + geom_point() + geom_text(data = . %>% filter(hwy > 28)) + ggtitle(unique(.$manufacurer)) I often create plots like in the example above to plot only subsets and would love to label automatically for the subset. At the moment, the . will not be recognised within