我正在努力制作帶有雙 y 軸的圖表。它沒有置信區間出現loess,我無法理解原因。
下面我報告代碼:
library(ggplot2)
library(readxl)
Dati <- data.frame("r" = c(0.99, 1.42, 2.10, 3.32, 6.09), "Vix" = c(16500, 19200, 22500, 24000, 26000), "OT" = c(23.5, 19, 11, 9, 7), "ref" = c("PU 178", "PU 178", "PU 178", "PU 178", "PU 178"))
attach(Dati)
scaleFactor <- max(Vix) / max(OT)
Graph <- ggplot(Dati, aes(x= r))
geom_point(aes(y= Vix, col=paste0("Vix ", ref)), shape = 1, size = 3.5)
geom_smooth(aes(y= Vix, col = paste0("Vix ", ref)), method="loess", level=0.55, se = TRUE)
geom_point(aes(y= OT * scaleFactor, col=paste0("OT ", ref)), shape = 1, size = 3.5)
geom_smooth(aes(y=OT * scaleFactor, col = paste0("OT ", ref)), method="loess", level=0.55, se = TRUE)
scale_color_manual(values=c('#644196', '#f92410', '#bba6d9', '#fca49c'),
name = "")
theme(legend.justification = "top")
scale_y_continuous(name="Viscosity at 10rpm (mPa s)", sec.axis=sec_axis(~./scaleFactor, name="open time (sec)"))
theme(
axis.title.y.left=element_text(color='#f92410'),
axis.text.y.left=element_text(color='#f92410'),
axis.title.y.right=element_text(color='#644196'),
axis.text.y.right=element_text(color='#644196'),
legend.position = "none"
)
scale_x_continuous(name="ratio A2333/AD5027")
Graph
結果是兩條線都完全沒有 CI。我認為它太大或太小指定level但也改變它我沒有得到 CI。我認為 5 個值太少而無法實作,但我在過去用 5 個值制作的圖表中沒有問題。
有人知道我是否犯了任何錯誤嗎?
下面我發布了我獲得的圖表。

做
uj5u.com熱心網友回復:
您的跨度太小(請參閱
Loess 在這里有點矯枉過正,您可以考慮其他
或 2 次多項式:
Dati %>% mutate(OT = OT*scaleFactor) %>%
pivot_longer(-c(r,ref)) %>%
mutate(name = paste0(name,ref)) %>%
ggplot(aes(x = r,y = value,col = name,fill = name))
geom_point(shape = 1, size = 3.5)
geom_smooth(method="lm",formula = y ~ poly(x, 2),alpha=0.1)
theme_bw()

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/364198.html
下一篇:只保存tsdiag中的一個圖
