我有以下情节:
在那里,我用Serial_number
因子的每个级别绘制数据框的拟合值。
我想摆脱所有错误的级别,意思是,只有带有608004650的Serial_number出现。
代码:
> head(APD)
# A tibble: 6 x 7
Serial_number Lot Wafer Amplification Voltage Dark_current pred
<fctr> <fctr> <fctr> <dbl> <dbl> <dbl> <dbl>
1 608004648 6 608 111.997 379.980 0.386364 1.550965
2 608004648 6 608 123.673 381.968 0.381323 1.572166
3 608004648 6 608 137.701 383.979 0.411581 1.594672
4 608004648 6 608 154.514 385.973 0.460648 1.618040
5 608004648 6 608 175.331 387.980 0.506632 1.642617
6 608004648 6 608 201.379 389.968 0.554607 1.668009
fit<- lmer(log(log(Amplification)) ~ poly(Voltage, 2) + (poly(Voltage, 2) | Serial_number), data = APD)
APD$pred<- fitted(fit)
ggplot(APD, aes(x = Voltage, y = log(log(Amplification)), colour = Serial_number==608004650)) +
geom_point(size=3) +
geom_line(aes(y = fitted(fit)),size=1)
编辑:缺少代码行来理解数据构造:
Limit data ranges:
APD.frame$Threshold<- "No"
APD.frame$Threshold[APD.frame$Amplification <= 150]<- "Yes"
APD.frame <- within(APD.frame,{
Threshold <- factor(Threshold)
})
APDmin<- APD.frame %>% group_by(Serial_number, Threshold) %>% top_n(n, Amplification)
APDmin<- APDmin[!APDmin$Threshold == "No", ]
APDmax<- APD.frame %>% group_by(Serial_number, Threshold) %>% top_n(-n, Amplification)
APDmax<- APDmax[!APDmax$Threshold == "Yes", ]
APD<- rbind(APDmin, APDmax)
APD<- with(APD, APD[order(Serial_number, Amplification),])
APD$Threshold<- NULL
最小可重复的示例(34个代码行+部分数据(~270行)):https://ufile.io/345np
编辑:当我不删除Threshold
列并应用相同的绘图命令时,我现在得到:
str(APD.frame <- read.table("4_APDs_irradiated.txt", header = TRUE, sep = "", dec = "."))
APD.frame <- within(APD.frame,{
Serial_number <- factor(Serial_number)
Irradiated <- factor(Irradiated, levels = c(0, 1), labels = c("no", "yes"))
})
APD.frame$Irradiated<- NULL
library(dplyr)
library(lme4)
APD.frame$Threshold<- "No"
APD.frame$Threshold[APD.frame$Amplification <= 150]<- "Yes"
n = 3
APDmin<- APD.frame %>% group_by(Serial_number, Threshold) %>% top_n(n, Amplification)
APDmin<- APDmin[!APDmin$Threshold == "No", ]
APDmax<- APD.frame %>% group_by(Serial_number, Threshold) %>% top_n(-n, Amplification)
APDmax<- APDmax[!APDmax$Threshold == "Yes", ]
APD<- rbind(APDmin, APDmax)
APD<- with(APD, APD[order(Serial_number, Amplification),])
summary(fit<- lmer(log(log(Amplification)) ~ poly(Voltage, 2) + (poly(Voltage, 2) | Serial_number), data = APD))
APD$pred<- fitted(fit)
APD %>% filter(Serial_number == "912009895") %>%
ggplot(aes(x = Voltage, y = log(log(Amplification)))) +
geom_line(aes(y = fitted(fit), size=2))
Error: Aesthetics must be either length 1 or the same as the data (6): y, size, x
答案 0 :(得分:0)
我有一个解决方法:
APD$SN<- "No"
APD$SN[APD$Serial_number == 912009895]<- "Yes"
One_APD<- subset(APD, SN=="Yes")
ggplot(One_APD, aes(x = Voltage, y = log(log(Amplification)))) +
geom_point(size=3, colour="blue") +
geom_line(aes(y = pred, size=0.5, alpha=0.2, colour="red")) +
theme(legend.position="none")
虽然它有效,但我感到惊讶的是,并没有像#34;掉落等级错误&#34; ..