【发布时间】:2023-04-09 15:54:01
【问题描述】:
我有这张桌子:
structure(list(Samples = structure(1:7, .Label = c("Sample1",
"Sample2", "sample3", "sample4", "sample5", "sample6", "sample7"
), class = "factor"), number_cycle = c(22L, 22L, 26L, 26L, 26L,
22L, 22L), Quality = structure(c(2L, 2L, 3L, 1L, 1L, 1L, 3L), .Label = c("Bad",
"Good", "Middle"), class = "factor"), Concentration = c(14L,
24L, 22L, 40L, 10L, 27L, 12L), Raw_reads = c(100000L, 5000L,
70000L, 340000L, 4789L, 50000L, 25000L)), class = "data.frame", row.names = c(NA,
-7L))
我想做一个散点图(raw_reads ~ 浓度),我可以观察到两个因素的分散:质量(颜色)和周期数(pch)。当我尝试这段代码时,我有一个没有任何意义的情节。
palette(rainbow(3))
plot(test$Raw_reads ~ test$Concentration,
col = test$Quality,
pch = test$number_cycle)
legend(x = "topleft",
legend = levels(test$Quality),
col = rainbow(3),
pch = test$number_cycle)
那么我该怎么做才能得到我的散点图呢?
感谢您的帮助。
【问题讨论】:
-
当我尝试你的代码时,我收到关于 "unimplemented pch value '26'" 的警告,我认为你应该对此进行调查。 (如果您将
number_cycle降级,使其所有数字都在0:25范围内,您会看到更多。尝试plot(0:25, 0:25, pch=0:25)进行演示。) -
或者直接设置
pch = as.numeric(as.factor(test$number_cycle))
标签: r scatter-plot