简体   繁体   中英

Ggplot graph: colour points by geom_point and colour trendlines by group

I am attempting to colour the raw data points, but I can't seem to find the information on how to do that, when I am already defining colours by group.

Data:

data = read.csv('TotMaxSize.csv')
structure(list(Column1 = 1:6, yrblock15 = c(2004L, 2004L, 2004L, 
2004L, 2004L, 2004L), circleID = 1:6, ThreeYearRain = c(748.9863518, 
744.4805429, 748.6081666, 747.5941999, 746.3382951, 740.9514718
), time = c(5.270172597, 4.270172617, 3.348596103, 3.019112219, 
2.905252281, 2.773856447), claylake = c(0, 0, 0, 0, 0.01, 0), 
    spinsandplain = c(99.53, 90.39, 50.7, 63.8, 73.65, 82.73), 
    TotMaxSize = c(2058.592458, 936.2305886, 1652.692998, 2162.200459, 
    1062.143104, 1863.051545)), row.names = c(NA, 6L), class = "data.frame")

Loaded packages:

library(ggplot2);library(lme4);library(ggeffects);library(dplyr) 

Model:

fit <- lmer(TotMaxSize~log(time)+spinsandplain+ThreeYearRain+claylake+ThreeYearRain*log(time)+(1|circleID),na.action=na.fail,data=data,REML=FALSE)

The plot:

mydf <- ggpredict(fit, terms = c("time[exp]","ThreeYearRain[647.6448,1198.882,1934.894]")) 
mydf1 <- rename(mydf, "time" = x, "TotMaxSize" = predicted)


ggplot(mydf1, aes(x = time, y = TotMaxSize, colour = group)) +
  geom_point(data = data, colour = "black")+
  stat_smooth(method = "lm", se = FALSE)+
  scale_colour_manual(values=c("skyblue2","dodgerblue3","darkblue"))+
  xlim(0,10)+ylim(0,7000)+
  xlab("time")+ylab("Max fire size")

It ends up looking like this:

在此处输入图像描述

Is there a way to colour geom_point (in a gradient) by the variable "ThreeYearRain"? I keep getting a similar error to other threads that I have read:

"Scale for 'colour' is already present. Adding another scale for 'colour', which will replace the existing scale."

You have defined the colour twice: once in aes(), and again in geom_point().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM