绘制x列和y列中的另一列,按R中的某个索引分组
我正在用R编写一个程序。我有这样一个数据集:绘制x列和y列中的另一列,按R中的某个索引分组,r,group-by,plot,ggplot2,R,Group By,Plot,Ggplot2,我正在用R编写一个程序。我有这样一个数据集: category x-value y-value 1 2 5 1 3 1 1 4 10 1 5 23 2 2 12 2 3 15 2 4
category x-value y-value
1 2 5
1 3 1
1 4 10
1 5 23
2 2 12
2 3 15
2 4 21
2 5 29
3 2 34
3 3 45
3 4 7
3 5 9
我想找到一种简单的方法,按“类别”对数据进行分组,并在一个xyplot上绘制这3组数据
谢谢 使用
ggplot2
?
像这样的
df = read.table(text = "
category x-value y-value
1 2 5
1 3 1
1 4 10
1 5 23
2 2 12
2 3 15
2 4 21
2 5 29
3 2 34
3 3 45
3 4 7
3 5 9", header = TRUE, sep = "")
library(ggplot2)
ggplot(df, aes(x.value, y.value, colour = factor(category))) + geom_point() +
geom_path()
还是这个
ggplot(df, aes(x.value, y.value, shape = factor(category),
colour = factor(category))) + geom_point(size = 5)
谢谢!这很整洁:)。最初我尝试使用subset()划分数据集,但这并不像您提供的那样整洁。仍在学习如何使用ggplot绘制漂亮的图形。@sprite728您可能喜欢阅读