1. coloring manual

1) geom_point, geom_line, etc.

grouping with color for discrete value

g <- ggplot(data = df)

g + geom_point(aes(x = var1,  y = var2, color = 'discrete variable name')) +

      geom_line(aes(x= var1, y = var2, color = 'discrete variable name'))+ 

      scale_color_manual('legend title', breaks = 'discrete variable name', values = 'color value')

# when drawing more than one point or line, breaks = c(), values = c()


grouping with color for continuous value

g <- ggplot(data = df)

g + geom_point(aes(x = var1,  y = var2, color = 'continuous variable name')) +

      geom_line(aes(x= var1, y = var2, color = 'continuous variable name'))+ 

      scale_color_continuous('legend title', low = 'color for low value', high = 'color for high value')

# scale_color_continuous can be exchanged with scale_color_gradient or scale_color_gradientn( n step gradient )


2) geom_bar, geom_hist, etc.

# almost same as above

... + scale_fill_manual('legend title', breaks = 'discrete variable name', values = 'color value')

# for coloring with discrete variable

... + scale_fill_continuous('legend title', low = 'color for low value', high = 'color for high value')

# for coloring with continuous variable


+ Recent posts