GGPLOT2:如何在ggplot()脚本中绘制特定选择 [英] GGPLOT2: how to plot specific selections inthe ggplot() script
问题描述
这是一个名为 P
的大型数据集的高峰,那里有10个拥有不同商店( SHP
)的特许经营权( CS
)有几个数值.数据集按星期( WK
)2 tm 52的顺序列出它们.它创建一个大文件.仅进入前6行的峰:
This is a peak into a large dataset named P
, where there are 10 concessionaries (CS
) that have different shops (SHP
) with several numeric values. The dataset lists them ordered by week (WK
) 2 tm 52. It creates a large file. A peak into just the 6 first rows:
WK,MND,CS,SHP,RevCY,RevLY,TCY,TLY,ACY,ALY
=========================================
2,JAN,AAA,AAA Shop 1,16834,16686,1837,1983,2853,3002
2,JAN,AAA,AAA Shop 2,95919,114696,9742,11813,20521,24673
2,JAN,BBB, BBB shop 1,93428,92212,7647,7857,18436,17984
2,JAN,BBB, BBB Shop 2,30600,35831,2748,3063,5579,6408
2,JAN,CCC, CCC Shop 1, 65229,78761,6074,7172,13852,16706
2,JAN,CCC, CCC Shop 2,465,754,73,118,92,162
我很难仅绘制与 SHP == AAA
有关的值.
I have difficulties plotting just the values that concern fi SHP==AAA
.
p <- ggplot(P, aes(WK, RevCY)) + geom_bar(stat="identity")
这正在绘制所有商店和所有 CS
.因此,潜在的问题是要了解如何仅从 CS = AAA
中绘制商店( SHP
).假设在 ggplot()+ geom_bar(stat ="identity")的x轴上是星期(
代码. WK
),在y轴上是 RevCY
)
This is plotting all shops and all CS
. So the underlying question is to understand how I can plot only the shops (SHP
) from CS=AAA
. Let's say with the weeks (WK
) on the x-axis and RevCY
on the y-axis in the ggplot() + geom_bar(stat="identity")
code.
这是正确的方向吗?:
p <- ggplot(P[P$CS=="AAA"], aes(WK, RevCY)) + geom_bar(stat="identity")
因此,无需创建各种子集即可直接进入 ggplot()
代码.希望我的问题清楚.
So without creating all kinds of subsets and straight into the ggplot()
code.
Hope my question is clear.
推荐答案
这对您有帮助吗?
ggplot(t, aes(WK, RevCY)) + geom_bar(data=subset(t,CS=="AAA"),stat="identity")
这篇关于GGPLOT2:如何在ggplot()脚本中绘制特定选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!