R散点图,未显示图例

R散点图,未显示图例,r,ggplot2,R,Ggplot2,我在R中有以下数据集,我想在散点图中绘制 user distance time 1 1 8.559737 4 2 1 5.013872 5 3 1 11.168995 9 4 1 4.059428 4 5 1 3.928071 4 6 1 12.403195 7 我使用下面的R代码生成我的绘图 plot <- ggplot(scatter, aes(x=scatter[['distance']]

我在R中有以下数据集,我想在散点图中绘制

     user  distance time
1    1  8.559737    4
2    1  5.013872    5
3    1 11.168995    9
4    1  4.059428    4
5    1  3.928071    4 
6    1 12.403195    7
我使用下面的R代码生成我的绘图

plot <- ggplot(scatter, aes(x=scatter[['distance']], y=scatter[['time']])) + 
          geom_point(shape=16, size=5, colour=scatter[['user']]) + 
          scale_x_continuous("Distance", limits=c(0,100), breaks=seq(0, 100, 10)) + 
          scale_y_continuous("Time", limits=c(0,20), breaks=seq(0, 20, 2))

png(filename="scatters/0_2_scatter.png", width=800, height=800)
plot(plot)
dev.off()
绘图尝试:

data
参数与
aes()
中的规范分开的全部目的是,ggplot执行非标准求值,允许您仅引用(无引号的)列名。不要通过
$
[[
[
[
aes()

绘制美学图时,图例应该出现(即使用
aes()
),而您没有将其用于颜色。

尝试:

ggplot(scatter, aes(x=distance, y=time)) + 
          geom_point(shape=16, size=5, mapping = aes(colour=user)) + 
          scale_x_continuous("Distance", limits=c(0,100), breaks=seq(0, 100, 10)) + 
          scale_y_continuous("Time", limits=c(0,20), breaks=seq(0, 20, 2))
数据
参数与
aes()
中的规范分开的全部目的是,ggplot进行非标准求值,允许您仅引用(未引用的)列名。永远不要通过
$
[
中的
[
专门引用列

绘制美学图时,图例应该出现(即使用
aes()
),而您没有使用颜色