尝试scale_linetype_manual以添加传奇,但不成功

发布于 2025-01-28 14:13:08 字数 3111 浏览 5 评论 0原文

遵循 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)

enter image description here

Can someone help me with the syntax? Why is it not generating the legend for me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜味超标? 2025-02-04 14:13:08

要获取传说,您必须在美学上映射,即在您的情况下,您必须在linepepe上映射:

library(nlme)
library(ggeffects)
library(ggplot2)

library(ggplot2)
ggplot() +
  geom_line(data = pred.mmlowW, aes(x = x, y = predicted, linetype = "pred.mmlowW")) +
  geom_line(data = pred.mmhighW, aes(x = x, y = predicted, linetype = "pred.mmhighW")) +
  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() +
  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"
    )
  )

“”

To get a legend you have to map on an aesthetic, i.e. in your case you have to map on linetype:

library(nlme)
library(ggeffects)
library(ggplot2)

library(ggplot2)
ggplot() +
  geom_line(data = pred.mmlowW, aes(x = x, y = predicted, linetype = "pred.mmlowW")) +
  geom_line(data = pred.mmhighW, aes(x = x, y = predicted, linetype = "pred.mmhighW")) +
  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() +
  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"
    )
  )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文