gpt4 book ai didi

r - 使用 ggplot2 facet wrap R 控制图表

转载 作者:行者123 更新时间:2023-12-05 05:19:46 24 4
gpt4 key购买 nike

我有下图:

enter image description here

这是使用 dplyr group_bysummarise 函数与 ggplot2 创建的:

slopes %>%
head(12) %>%
inner_join(word_month_counts, by = "word") %>%
mutate(word = reorder(word, -estimate)) %>%
ggplot(aes(month, prop_per_month, color = word)) +
geom_line(show.legend = FALSE,lwd=1.3) +
geom_smooth(se=FALSE,lty=2)+
facet_wrap(~ word, scales = "free_y")

我想用控制图替换它,我看过 herehere但在使用 facet_wrap

时似乎无法锻炼如何合并

我一直在玩 qcc 和 qicharts,比如:

library(qicharts)

Datetime <- c("2015-09-29AM", "2015-09-29PM" ,"2015-09-30AM", "2015-09-30PM", "2015-10-01AM" ,"2015-10-01PM"
,"2015-10-02AM", "2015-10-02PM" ,"2015-10-03AM" ,"2015-10-03PM", "2015-10-04AM" ,"2015-10-04PM"
,"2015-10-05AM", "2015-10-05PM", "2015-10-06AM" ,"2015-10-06PM")
FailRate_M1 <- c(5045,4350,4350,3975,4290,4430,4485,4285,3980,3925,3645,3760,3300,3685,3463,5200)

df1 <- data.frame(Datetime,FailRate_M1)

qic(FailRate_M1,
x = Datetime,
data = df1,
chart = 'c',
runvals = TRUE,
cex = 1.2,
main = 'Measurement Fail Rate (M1)',
ylab = 'MFR (%)',
xlab = 'Datetime')

任何带有 ggplot2 facet_wrap 的指针或代码示例将不胜感激

最佳答案

你可以试试:

# as you provided no reproducible example, I added afactor gr for the facet.
df1 <- data.frame(Datetime,FailRate_M1, gr=gl(2,8) )

# calculate the cl, ucl and lcl per group
df2 <- lapply(split(df1, df1$gr), function(data){
a <- qic(FailRate_M1,
x = Datetime,
data = data,
chart = 'c',
runvals = TRUE)
cbind.data.frame(ucl=a$ucl,cl= a$cl, lcl= a$lcl)
})

# the final data.frame
df3 <- cbind(df1, do.call(rbind,df2))

# and the final plot
ggplot(df3, aes(x=Datetime, y=FailRate_M1, group=gr)) +
geom_line(show.legend = FALSE,lwd=1.3) +
geom_line(aes(x=Datetime, y=ucl)) +
geom_line(aes(x=Datetime, y=cl)) +
geom_line(aes(x=Datetime, y=lcl)) +
facet_wrap(~ gr, scales = "free_x")

enter image description here

关于r - 使用 ggplot2 facet wrap R 控制图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45548089/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com