带有ggplot2的条形图中的条形图 [英] Bar in Bar Chart with ggplot2

查看:71
本文介绍了带有ggplot2的条形图中的条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用ggplot2在R的条形图中绘制条形,如下图所示.我想比较期望值和实际值,并想生成一个类似于下图的图.我提供了一些伪代码:

Is it possible to plot bar in bar chart in R with ggplot2 like the figure below. I want to compare expected and actual values and I want to generate a figure similar to the figure below. I have provided some dummy code:

 library(tidyverse)

df = data_frame(name = letters[1:10],profit = rnorm(mean = 100, sd = 20, n = 10),
            target = profit + rnorm(mean = 10, sd = 10, n = 10))

   df %>% ggplot(aes(x = name, y = profit)) + geom_bar(stat = "identity") 

推荐答案

是的,请查看ggplot文档

Yes it is possible, look at ggplot documentation

library(tidyverse)

df = data_frame(name = letters[1:10],profit = rnorm(mean = 100, sd = 20, n = 10),
                target = profit + rnorm(mean = 10, sd = 10, n = 10))

ggplot(df,aes(x=name,y=profit))+geom_bar(stat= "identity")+
geom_bar(aes(x= name,y=target),stat= "identity", width = 0.1,col = "green",fill="green")

这篇关于带有ggplot2的条形图中的条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆