尝试scale_linetype_manual以添加传奇,但不成功
遵循 sell the the the the the the the the the (name =“新传奇标题”)但是传奇标题仍然没有更改,我现在只想根据行类型生成Legend的行绘图,但没有成功。
dataFrame如下我以前的reproduciblitiy的下面如下:
#For lowW dataset:
SurfaceCoverage <- c(0.04,0.08,0.1,0.12,0.15,0.2,0.04,0.08,0.1,0.12,0.15,0.2)
TotalSurfaceEnergy <- c(139.31449,105.17776,105.38411,99.27608,92.29064,91.55114,84.44251,78.40453,74.66656,73.33242,72.42429,77.08666)
sample <- c(1,1,1,1,1,1,2,2,2,2,2,2)
lowW <- data.frame(sample,SurfaceCoverage,TotalSurfaceEnergy)
lowW$sample <- sub("^", "Wettable", lowW$sample)
lowW$RelativeHumidity <- "Low relative humidity"; lowW$group <- "Wettable"
lowW$sR <- paste(lowW$sample,lowW$RelativeHumidity)
dflowW <- data.frame(
"y"=c(lowW$TotalSurfaceEnergy),
"x"=c(lowW$SurfaceCoverage),
"b"=c(lowW$sample),
"sR"=c(lowW$sR)
)
mixed.lme <- lme(y~log(x),random=~1|b,data=dflowW)
pred.mmlowW <- ggpredict(mixed.lme, terms = c("x"))
#For highW dataset:
SurfaceCoverage <- c(0.02,0.04,0.06,0.08,0.1,0.12,0.02,0.04,0.06,0.08,0.1,0.12)
TotalSurfaceEnergy <- c(66.79554,61.46907,57.56855,54.00953,54.28361,55.15855,50.72314,48.55892,47.41811,43.70885,42.13757,40.55924)
sample <- c(1,1,1,1,1,1,2,2,2,2,2,2)
highW <- data.frame(sample,SurfaceCoverage,TotalSurfaceEnergy)
highW$sample <- sub("^", "Wettable", highW$sample)
highW$RelativeHumidity <- "High relative humidity"; highW$group <- "Wettable"
highW$sR <- paste(highW$sample,highW$RelativeHumidity)
dfhighW <- data.frame(
"y"=c(highW$TotalSurfaceEnergy),
"x"=c(highW$SurfaceCoverage),
"b"=c(highW$sample),
"sR"=c(highW$sR)
)
mixed.lme <- lme(y~log(x),random=~1|b,data=dfhighW)
pred.mmhighW <- ggpredict(mixed.lme, terms = c("x"))
用于生成线路图:
p <- ggplot() +
#lowa plot
geom_line(data=pred.mmlowW, aes(x = x, y = predicted)) +
#higha plot
geom_line(data=pred.mmhighW, aes(x = x, y = predicted)) +
xlim(0.01,0.2) +
ylim(30,150) +
labs(title = "") +
ylab(bquote('Total Surface Energy ' (mJ/m^2))) +
xlab(bquote('Surface Coverage ' (n/n[m]) )) +
theme_minimal()
print(p)
我尝试添加传说的内容,但没有成功:
p1 <- p + scale_linetype_manual(name = "New Legend Title",
values = c("solid","dashed"),
breaks=c("pred.mmlowW",
"pred.mmhighW",
),
labels=c("wettable soil, 0% relative humidity",
"water-repellent soil, 0% relative humidity"
))
print(p1)
有人可以帮助我使用语法吗?为什么它不为我产生传奇?
Following the thread from Tried p + scale_fill_discrete(name = "New Legend Title") but legend title still not changing, I now only want to generate line plot with legend based on the line type but has been unsuccessful.
Dataframe as below from my previous thread for reproduciblitiy:
#For lowW dataset:
SurfaceCoverage <- c(0.04,0.08,0.1,0.12,0.15,0.2,0.04,0.08,0.1,0.12,0.15,0.2)
TotalSurfaceEnergy <- c(139.31449,105.17776,105.38411,99.27608,92.29064,91.55114,84.44251,78.40453,74.66656,73.33242,72.42429,77.08666)
sample <- c(1,1,1,1,1,1,2,2,2,2,2,2)
lowW <- data.frame(sample,SurfaceCoverage,TotalSurfaceEnergy)
lowW$sample <- sub("^", "Wettable", lowW$sample)
lowW$RelativeHumidity <- "Low relative humidity"; lowW$group <- "Wettable"
lowW$sR <- paste(lowW$sample,lowW$RelativeHumidity)
dflowW <- data.frame(
"y"=c(lowW$TotalSurfaceEnergy),
"x"=c(lowW$SurfaceCoverage),
"b"=c(lowW$sample),
"sR"=c(lowW$sR)
)
mixed.lme <- lme(y~log(x),random=~1|b,data=dflowW)
pred.mmlowW <- ggpredict(mixed.lme, terms = c("x"))
#For highW dataset:
SurfaceCoverage <- c(0.02,0.04,0.06,0.08,0.1,0.12,0.02,0.04,0.06,0.08,0.1,0.12)
TotalSurfaceEnergy <- c(66.79554,61.46907,57.56855,54.00953,54.28361,55.15855,50.72314,48.55892,47.41811,43.70885,42.13757,40.55924)
sample <- c(1,1,1,1,1,1,2,2,2,2,2,2)
highW <- data.frame(sample,SurfaceCoverage,TotalSurfaceEnergy)
highW$sample <- sub("^", "Wettable", highW$sample)
highW$RelativeHumidity <- "High relative humidity"; highW$group <- "Wettable"
highW$sR <- paste(highW$sample,highW$RelativeHumidity)
dfhighW <- data.frame(
"y"=c(highW$TotalSurfaceEnergy),
"x"=c(highW$SurfaceCoverage),
"b"=c(highW$sample),
"sR"=c(highW$sR)
)
mixed.lme <- lme(y~log(x),random=~1|b,data=dfhighW)
pred.mmhighW <- ggpredict(mixed.lme, terms = c("x"))
For generating the line plot:
p <- ggplot() +
#lowa plot
geom_line(data=pred.mmlowW, aes(x = x, y = predicted)) +
#higha plot
geom_line(data=pred.mmhighW, aes(x = x, y = predicted)) +
xlim(0.01,0.2) +
ylim(30,150) +
labs(title = "") +
ylab(bquote('Total Surface Energy ' (mJ/m^2))) +
xlab(bquote('Surface Coverage ' (n/n[m]) )) +
theme_minimal()
print(p)
What I have tried on adding the legend but has been unsuccessful:
p1 <- p + scale_linetype_manual(name = "New Legend Title",
values = c("solid","dashed"),
breaks=c("pred.mmlowW",
"pred.mmhighW",
),
labels=c("wettable soil, 0% relative humidity",
"water-repellent soil, 0% relative humidity"
))
print(p1)
Can someone help me with the syntax? Why is it not generating the legend for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要获取传说,您必须在美学上映射,即在您的情况下,您必须在
linepepe
上映射:To get a legend you have to map on an aesthetic, i.e. in your case you have to map on
linetype
: