E B*_*E B 2 r bar-chart ggplot2
我正在尝试更改 ggplot 中多变量图的标签我的第一张图片是这样的:
第一张图片显示我有两个变量 - Count 和 Total Gross 我有 x 标签作为 G 和 N(这是我在数据中的变量值)我想将 x 标签更改为更具描述性
如何更新我的 ggplot 语句以引入这些新标签
test %>%
group_by(DiscInd) %>%
summarise(Count=n(),TotalGross=sum(Gross)/100000000) %>%
gather(Var, Val, -DiscInd) %>%
ggplot(., aes(x=DiscInd, y = Val, fill=Var)) +
geom_bar(stat="identity", position="dodge") +
xlab("Year vs Released Difference") +
ylab("Total Gross") +
ggtitle("Total Movie with Gross ")
Run Code Online (Sandbox Code Playgroud)
这可能吗?
这是我的数据框测试的一些记录
DiscInd Gross
N 2783918982
N 2207615668
N 1670328025
N 1519479547
G 1514019071
G 1404705868
Run Code Online (Sandbox Code Playgroud)
更新:我还试图更改标签和格式标签,使其不会相互重叠。
假设您的新描述性标签名称是Label G Desc和Label N Desc,这是您想要的吗?
test %>%
group_by(DiscInd) %>%
summarise(Count=n(),TotalGross=sum(Gross)/100000000) %>%
gather(Var, Val, -DiscInd) %>%
ggplot(., aes(x=DiscInd, y = Val, fill=Var)) +
geom_bar(stat="identity", position="dodge") +
scale_x_discrete(labels=c("Label G Desc", "Label N Desc")) +
xlab("Year vs Released Difference") +
ylab("Total Gross") +
ggtitle("Total Movie with Gross ")
Run Code Online (Sandbox Code Playgroud)
带角度的 x 轴文本:
test %>%
group_by(DiscInd) %>%
summarise(Count=n(),TotalGross=sum(Gross)/100000000) %>%
gather(Var, Val, -DiscInd) %>%
ggplot(., aes(x=DiscInd, y = Val, fill=Var)) +
geom_bar(stat="identity", position="dodge") +
scale_x_discrete(labels=c("Label G Desc", "Label N Desc")) +
xlab("Year vs Released Difference") +
ylab("Total Gross") +
ggtitle("Total Movie with Gross ") +
theme(axis.text.x = element_text(angle = 60, size=15, hjust = 1))
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11558 次 |
最近记录: |