我正在尝试按第4列对输入表进行子集化,有很多不同的字符串:
a 1 3 led a.1.3.led 10 38
a 3 4 led a.3.4.led 11 40
b 1 2 dad b.3.4.dad 20 125
b 2 4 dad b.2.4.dad 80 222
c 1 10 lik c.1.5.lik 100 250
我想用第四列中的不同字符串将其分开并绘制图表。你能帮我分一下吗?
谢谢
答案 0 :(得分:0)
我不清楚你想要什么,但是它是这样的,
df <- structure(list(V1 = structure(c(1L, 1L, 2L, 2L, 3L), .Label = c("a",
"b", "c"), class = "factor"), V2 = c(1L, 3L, 1L, 2L, 1L), V3 = c(3L,
4L, 2L, 4L, 10L), V4 = structure(c(2L, 2L, 1L, 1L, 3L), .Label = c("dad",
"led", "lik"), class = "factor"), V5 = structure(c(1L, 2L, 4L,
3L, 5L), .Label = c("a.1.3.led", "a.3.4.led", "b.2.4.dad", "b.3.4.dad",
"c.1.5.lik"), class = "factor"), V6 = c(10L, 11L, 20L, 80L, 100L
), V7 = c(38L, 40L, 125L, 222L, 250L)), .Names = c("V1", "V2",
"V3", "V4", "V5", "V6", "V7"), class = "data.frame", row.names = c(NA,
-5L))
df
#> V1 V2 V3 V4 V5 V6 V7
#> 1 a 1 3 led a.1.3.led 10 38
#> 2 a 3 4 led a.3.4.led 11 40
#> 3 b 1 2 dad b.3.4.dad 20 125
#> 4 b 2 4 dad b.2.4.dad 80 222
#> 5 c 1 10 lik c.1.5.lik 100 250
# install.packages(c("tidyverse"), dependencies = TRUE)
library(ggplot2)
ggplot(df, aes(x = V3, y = V6)) + geom_point() + facet_wrap(~V4)
或可能
ggplot(subset(df, V4 %in% c("led" , "dad"))) +
geom_point(aes(x = V3, y = V6)) +
labs(title = "Only `led' , `dad' from the 4th column")