Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
一个RStudio中的多个绘图_R_Plot_Scatter Plot - Fatal编程技术网

一个RStudio中的多个绘图

一个RStudio中的多个绘图,r,plot,scatter-plot,R,Plot,Scatter Plot,我正在寻找一个情节的前20名游戏的销售4类(欧盟,JP,NA和其他)在一个情节 我用下面的代码为每一个都抽取了前20名: # creating a scatterplot of the top 20 in each category top20NA <- head(sort(games$NA_Sales,decreasing=TRUE), n = 20) top20EU <- head(sort(games$EU_Sales,decreasing=TRUE), n = 20) top

我正在寻找一个情节的前20名游戏的销售4类(欧盟,JP,NA和其他)在一个情节

我用下面的代码为每一个都抽取了前20名:

# creating a scatterplot of the top 20 in each category
top20NA <- head(sort(games$NA_Sales,decreasing=TRUE), n = 20)
top20EU <- head(sort(games$EU_Sales,decreasing=TRUE), n = 20)
top20JP <- head(sort(games$JP_Sales,decreasing=TRUE), n = 20)
top20other <- head(sort(games$Other_Sales,decreasing=TRUE), n = 20)
x轴应为排名,y轴应为销售

有什么想法吗?提前谢谢


您可以使用par()函数在同一窗口中绘制多个散点图

par(mfrow=c(2,2))
plot(top20NA, col ="Blue", ylab="Sales", xlab="Ranking")
plot(top20EU, col = "Black", ylab="Sales", xlab="Ranking")
plot(top20JP, col = "Yellow", ylab="Sales", xlab="Ranking")
plot(top20other, col = "Green", ylab="Sales", xlab="Ranking")
如果要在同一绘图上绘制所有系列,可以使用lines()和points()函数

plot(top20NA, ylim = c(0,15), col = "Blue", type = "b",
 ylab="Sales", xlab="Ranking")
points(top20EU, col = "Black")
lines(top20EU, col = "Black")
points(top20JP, col = "Yellow")
lines(top20JP, col = "Yellow")
points(top20other, col = "Green")
lines(top20other, col = "Green")

诚然,这在BaseR中有点笨拙,但它确实完成了任务

拥有一段数据会非常有帮助,无论如何我会选择
dplyr
ggplot

  • 合并您的数据,每场比赛有一行,两列用于索引和销售
  • >库(dplyr)
    >虹膜%>%
    +选择(种类、花瓣长度、萼片长度)%>%
    +总目()
    种花瓣。长萼片。长
    1 setosa 1.4 5.1
    2 setosa 1.4.9
    3 setosa 1.3 4.7
    4 setosa 1.5 4.6
    5 setosa 1.4 5.0
    6.1.7.5.4
    
  • 现在,您可以在《美学》中使用
    color=yourvar
    shape=yourvar
    绘制散点图,以区分不同的游戏
  • 库(dplyr)
    图书馆(GG2)
    虹膜%>%
    选择(种类、花瓣长度、萼片长度)%>%
    ggplot(aes(花瓣长度、萼片长度、颜色=种类、形状=种类))+
    几何点()
    
    这会给你类似的东西:

    使用
    ggplot2可能会更容易些。嗨,Jalind,我希望创建一个具有4种不同颜色的绘图,这将生成4种不同的绘图。你知道可以合并吗?嗨,加里。我已经更新了答案,允许在同一个绘图上绘制多个系列。
    
    plot(top20NA, ylim = c(0,15), col = "Blue", type = "b",
     ylab="Sales", xlab="Ranking")
    points(top20EU, col = "Black")
    lines(top20EU, col = "Black")
    points(top20JP, col = "Yellow")
    lines(top20JP, col = "Yellow")
    points(top20other, col = "Green")
    lines(top20other, col = "Green")