Home > Blockchain >  Color geom_point based on y axis intervals and add linear regression line
Color geom_point based on y axis intervals and add linear regression line

Time:01-12

I am interested in learning how to color my scatterplot so that the points are colored based on intervals on the y-axis. I would like to code the following: <10 = blue, 10-20 = orange, 20-30 = green, & >30=purple. Currently, I have color set to factor(n_ct) and I'm getting a rainbow. Also, I keep getting a warning message that says "Width not defined. Set with 'position_dodge(width =?)" even though I have position = "dodge" in there, so I don't know if that is my mistake or rstudios. I would also like to add a line of regression.

performance <- read_csv(performance.csv)
cumulative <- read_csv(cumulative.csv)

performance_2_n_ct <performance %>% select(Sample, AvgCov)
cumulative_2_n_ct <- cumulative %>% select(Sample, n_ct)

cumulative_3_n_ct <- cumulative_2_n_ct %>%
filter(!is.na(n_ct))

all_data_n_ct_ <- left_join(cumulative_3_n_ct, performance_2_n_ct, by = "Sample")

n_ct_finale <- ggplot(data = all_data_n_ct_, aes(y=n_ct, x = AvgCov, color = factor(n_ct)))  
 geom_point(stat = "identity", position = "dodge")

Image of what I have is below.

enter image description here

If you have specific colors that you want to use, you can use scale_color_manual():

...  
scale_color_manual(values = c("red", 
                                "cornflowerblue",
                                "green",
                                "purple"))

enter image description here

  •  Tags:  
  • Related