【发布时间】:2020-01-08 00:38:36
【问题描述】:
我无法为我的数据绘制散点图。我有 1 个自变量“应变”,我有 3 个解释值。查看结构数据框
'data.frame': 30 obs. of 4 variables:
$ Strain : Factor w/ 30 levels "1","10","11",..: 1 12 14 15 25 27 28 29 30 2 ...
$ second_hour : Factor w/ 30 levels "10356.3888888889",..: 15 16 8 14 7 6 11 10 13 12 ...
$ second_hour_n: Factor w/ 30 levels "10149.4751953184",..: 5 4 15 6 18 19 13 14 9 12 ...
$ Beula : num 21674 21308 19905 20817 20017 ...
> head(hour_2)
Strain second_hour second_hour_n Beula
1 1 19354.4444444444 12103.3628274451 21673.72
2 2 20021.2222222222 11577.7991047524 21307.61
3 3 16105.9444444444 14425.8808435683 19905.39
4 4 18993.3888888889 12149.3204615723 20816.78
5 5 15541.3888888889 15370.8433645383 20016.94
6 6 14767.1666666667 16288.3635541566 19000.44
我想在散点图中绘制每个带颜色编码的菌株的每个解释值。
在我目前的尝试中,我首先使用以下代码融化数据框:
> hour_2_melted <- melt(hour_2, id.vars = "Strain")
Warning message:
attributes are not identical across measure variables; they will be dropped
然后我绘制
ggplot(hour_2_melted, aes(Strain, value)) + geom_point()
但是 Y 轴不能更改,因为它是连续的,我不希望每个值都显示在 y 轴上。 x轴的顺序也很奇怪。最后,如何对 3 个不同的解释值进行颜色编码?
感谢任何帮助。
【问题讨论】:
-
您能否提供一个可重现的数据集示例?见:stackoverflow.com/questions/5963269/…
-
意外的绘图是因为您已将三列数据作为“因子”导入,而您几乎肯定希望它们为数字。在导入时更改上游,或使用
hour_2$Strain = as.numeric(as.character(hour_2$Strain))等转换为数字。