带有ggplot的R脚本的奇怪轴图

带有ggplot的R脚本的奇怪轴图,r,ggplot2,R,Ggplot2,这是我的R脚本: #!/usr/bin/env Rscript library (ggplot2) data = read.table ("downloads.txt", header=T) data$number = factor (data$Size) data$PITtype = factor (data$PITtype) g.all <- ggplot (data, aes (x=Time, y=number, color=PITtype)) + geom_point

这是我的R脚本:

#!/usr/bin/env Rscript 

library (ggplot2)

data = read.table ("downloads.txt", header=T)
data$number = factor (data$Size)
data$PITtype = factor (data$PITtype)

g.all <- ggplot (data, aes (x=Time, y=number, color=PITtype)) +
  geom_point (size=2) +
  geom_line () +
  ylab ("# Pending Downloads") +
  theme_bw ()

png ("pendingDownloads_graph.png", width=800, height=800)
print (g.all)
x = dev.off ()
我得到了一张奇怪的图(见全黑的“y”轴)和一个错误:geom_路径:每组只包含一个观测值。您是否需要调整团队美学


怎么了?

您不需要创建
number
列,甚至不需要
ggplot2
。你可以做:

> plot(data$Size, data$Time)
得到一个简单的散点图

ggplot2
解决方案有点漂亮,因为您只有一个
PITtype
,所以没有必要包含它:

> ggplot(data,aes(x=Time,y=Size))+geom_point()+geom_line()
如果您的数据多于on
PITtype
,并且希望以不同的颜色显示这些点,请将其包括在内:

> ggplot(data,aes(x=Time,y=Size,col=PITtype))+geom_point()+geom_line()

但是你可能应该阅读一些基本的R文档,在那里你会比这里更快地找到答案。

因为你已经创建了
number
作为一个因子,并且每个数字都是唯一的,所以你有一个因子,它的级别和行数一样多。你想在这里干什么?为什么要创建一个因子?我不知道如何使用R,我只重写一个脚本。我只想知道尺寸是如何随时间增加的。
> ggplot(data,aes(x=Time,y=Size,col=PITtype))+geom_point()+geom_line()