选定变量名称的箱线图
Boxplot of a selected variable name
如何为变量 2(7 个观测值)中的“N”个值生成箱线图。
Variable1 <- c(rep("E",7), rep("N",7),rep("L",7))
Variable2 <- c(rep(1:7, 3))
value <- c(12.44035, 11.98035333, 11.40821, 12.15833, 13.14826, 11.99339667, 12.17363, 4.073096, 3.946134667, 6.244152, 5.76892, 4.545772, 3.580206667, 2.879470667, 3.6912875, 3.501247, 2.684179, 3.06306, 3.364774, 4.485021333, 3.373649333)
dff <- data.frame(Variable1, Variable2, value)
我试过了,但没有显示我想要的:
ggplot(dff, aes(x=Variable1$N, y=value)) +
geom_boxplot()
这将是我想要的输出:
也许是这样:
library(ggplot2)
library(dplyr)
#Code
dff %>% filter(Variable1=='N') %>%
ggplot(aes(x=factor(Variable2),y=value))+
geom_boxplot()
输出:
或者这样:
#Code 2
dff %>%
ggplot(aes(x=factor(Variable2),y=value))+
geom_boxplot()
输出:
如何为变量 2(7 个观测值)中的“N”个值生成箱线图。
Variable1 <- c(rep("E",7), rep("N",7),rep("L",7))
Variable2 <- c(rep(1:7, 3))
value <- c(12.44035, 11.98035333, 11.40821, 12.15833, 13.14826, 11.99339667, 12.17363, 4.073096, 3.946134667, 6.244152, 5.76892, 4.545772, 3.580206667, 2.879470667, 3.6912875, 3.501247, 2.684179, 3.06306, 3.364774, 4.485021333, 3.373649333)
dff <- data.frame(Variable1, Variable2, value)
我试过了,但没有显示我想要的:
ggplot(dff, aes(x=Variable1$N, y=value)) +
geom_boxplot()
这将是我想要的输出:
也许是这样:
library(ggplot2)
library(dplyr)
#Code
dff %>% filter(Variable1=='N') %>%
ggplot(aes(x=factor(Variable2),y=value))+
geom_boxplot()
输出:
或者这样:
#Code 2
dff %>%
ggplot(aes(x=factor(Variable2),y=value))+
geom_boxplot()
输出: