You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks to http://r4ds.had.co.nz/ I can riff on your idea and point out that the "do" function doesn't play well with other columns. A little more purrr and some tidyr and you can work with many list columns.
library(ggpmisc) # for annotation
library(tidyr) # for nest
plots <- small_pwt %>%
mutate( country = as.character( country ) ) %>%
group_by(country) %>%
nest %>%
mutate( avhlm = map( data
, function( DF ) {
lm( avh ~ year, data = DF )
}
)
) %>%
mutate( plot = pmap( .
, function( country, data, avhlm ) {
ggplot( data, aes( y = avh, x = year ) ) +
theme_tufte() +
geom_line() +
geom_smooth( method = "lm" ) +
stat_poly_eq( formula = y ~ x
, aes( label = paste( ..eq.label..
, ..rr.label..
, sep = "*\",\"~~~"
)
)
, label.y.npc = "bottom"
, parse = TRUE
) +
ggtitle( country ) +
ylab( "Year") +
xlab( "Average annual hours worked by persons engaged")
}
)
)
# RStudio keeps a history you can surf through
walk( plots$plot, print )
The text was updated successfully, but these errors were encountered:
Thanks to http://r4ds.had.co.nz/ I can riff on your idea and point out that the "do" function doesn't play well with other columns. A little more purrr and some tidyr and you can work with many list columns.
The text was updated successfully, but these errors were encountered: