简体   繁体   English

如何在R中绘制支出与年份

[英]how to plot a expenditure vs year in r

I have a dataset which has about 100,000 datapoints. 我有一个约有100,000个数据点的数据集。 I want to plot two columns. 我想绘制两列。

  1. Y axis - Year Y轴-年
  2. X axis - Sales X轴-销售

Sample Data: 样本数据:

Sales Year 22 2016 10 2016 3.99 2017 8.99 2017 12.99 2017 8.00 2016 12.00 2017 5.00 2016 22 2017 50 2016 53 2017 销售年份22 2016 10 2016 3.99 2017 8.99 2017 12.99 2017 8.00 2016 12.00 2017 5.00 2016 22 2017 50 2016 53 2017

Im using the following code 我正在使用以下代码

plot(subset_4$SALES ~ subset_4$YEAR)

在此处输入图片说明

But the plot doesn't look great. 但是情节看起来并不好。 Is there any nicer way of doing this? 有更好的方法吗?

Update: plot(subset_4$SALES ~ subset_4$WEEKS) 更新:情节(subset_4 $ SALES〜subset_4 $ WEEKS) 在此处输入图片说明

You can try ggplot2 library 您可以尝试ggplot2库

df <- data.frame(sales, year)

ggplot(df, aes(x = sales, y = year, color = year)) +
  geom_point() +
  xlab("Sales") +
  ylab("Year")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM