![]() ![]() ![]() Ggplot(aes(x = time, y = value, color = substr(name, 1, 4), group = name)) + It's a bit hacky but it's short, effective, and all gets done in the plotting code without extra data wrangling, post-hoc changes or a long vector of colour mappings. You could just use the first four characters of name for the colour aesthetic (using substr), and the full name as a group aesthetic. Ggplot(aes(x=time, y=value, color=name)) + geom_line() # time actual estimate boot_1 boot_2 boot_3 boot_4 boot_5 boot_6 boot_7 I know there's a lot of brute ways of doing this by some combo of a) creating some auxiliary variables in the data-frame based on the string-pattern that will server as my color/size group, then b) generating the plot below, extracting all the color-layer info, and then filling out an entire scale_color_manual() and scale_size_manual() map, and c)replacing the 'boot_*' values with "grey."Īre there any versatile shortcuts here? library(dplyr)ĭf=tibble(time=c(1:5), actual=2*time+3, estimate = actual+rnorm(length(actual)))ĭf = df$estimate + rnorm(nrow(df)) In the example below, I basically want to make all the boot_* lines gray and skinny, while I want all other lines to retain the default colors/widths otherwise being used. In ggplot, is there any simple way of overriding the line attributes of a single group(s) without having to specify the entirety of the color/line pallet via scale_*_manual()? ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |