geom-bar

How to add frequency count labels to the bars in a bar graph using ggplot2? [duplicate]

泪湿孤枕 提交于 2019-11-26 20:00:40
问题 This question already has an answer here: Show frequencies along with barplot in ggplot2 5 answers I want to plot frequency distribution of an [r] factor variable as a bargraph, where bars represent the frequency counts of the factor levels. I use ggplot2 to do that and there's no problem with that. What I can't figure out is how to add frequency count labels to the bars in the bargraph. The syntax that I've tried is as follows: ggplot(data, aes(x = factorvar)) + geom_bar(fill = "somecolor")

ggplot2 geom_bar - how to keep order of data.frame [duplicate]

守給你的承諾、 提交于 2019-11-26 18:34:20
问题 This question already has answers here : Order Bars in ggplot2 bar graph (12 answers) Closed 21 days ago . I have a question concerning the order of data in my geom_bar . This is my dataset: SM_P,Spotted melanosis on palm,16.2 DM_P,Diffuse melanosis on palm,78.6 SM_T,Spotted melanosis on trunk,57.3 DM_T,Diffuse melanosis on trunk,20.6 LEU_M,Leuco melanosis,17 WB_M,Whole body melanosis,8.4 SK_P,Spotted keratosis on palm,35.4 DK_P,Diffuse keratosis on palm,23.5 SK_S,Spotted keratosis on sole,66

Bars in geom_bar have unwanted different widths when using facet_wrap

做~自己de王妃 提交于 2019-11-26 17:06:26
问题 I can'd find a solution for the following problem(s). I would appreciate some help a lot! The following code produces bar charts using facet. However, due to "extra space" ggplot2 has in some groups it makes the bars much wider, even if I specify a width of 0.1 or similar. I find that very annoying since it makes it look very unprofessional. I want all the bars to look the same (except for the fill). I hope somebody can tell me how to fix this. Secondly, how can I reorder the different

ggplot: Order bars in faceted bar chart per facet

喜欢而已 提交于 2019-11-26 16:43:50
问题 I have a dataframe in R that I want to plot in a faceted ggplot bar chart. I use this code in ggplot: ggplot(data_long, aes(x = partei, y = wert, fill = kat, width=0.75)) + labs(y = "Wähleranteil [ % ]", x = NULL, fill = NULL) + geom_bar(stat = "identity") + facet_wrap(~kat) + coord_flip() + guides(fill=FALSE) + theme_bw() + theme( strip.background = element_blank(), panel.grid.major = element_line(colour = "grey80"), panel.border = element_blank(), axis.ticks = element_line(size = 0), panel

ggplot replace count with percentage in geom_bar

人走茶凉 提交于 2019-11-26 16:35:00
问题 I have a dataframe d : > head(d,20) groupchange Symscore3 1 4 1 2 4 2 3 4 1 4 4 2 5 5 0 6 5 0 7 5 0 8 4 0 9 2 2 10 5 0 11 5 0 12 5 1 13 5 0 14 4 1 15 5 1 16 1 0 17 4 0 18 1 1 19 5 0 20 4 0 That I am plotting with: ggplot(d, aes(groupchange, y=..count../sum(..count..), fill=Symscore3)) + geom_bar(position = "dodge") In this way each bar represents its percentage on the whole data. Instead I would like that each bar represents a relative percentage; i.e. the sum of the bar in obtained with

ggplot bar plot with facet-dependent order of categories

做~自己de王妃 提交于 2019-11-26 16:33:07
I've seen many questions (often linked to Order Bars in ggplot2 bar graph ) about how to (re)order categories in a bar plot. What I am after is just a touch different, but I haven't found a good way to do it: I have a multi-faceted bar plot, and I want to order the x axis for each facet independently, according to another variable (in my case, that variable is just the y value itself, i.e. I just want the bars to go in increasing length in each facet). Simple example, following e.g. Order Bars in ggplot2 bar graph : df <- data.frame(name=c('foo','bar','foo','bar'),period=c('old','old','recent'

ggplot2 and a Stacked Bar Chart with Negative Values

不羁岁月 提交于 2019-11-26 16:11:20
Given the following dataset: Division Year OperatingIncome 1 A 2012 11460 2 B 2012 7431 3 C 2012 -8121 4 D 2012 15719 5 E 2012 364 6 A 2011 12211 7 B 2011 6290 8 C 2011 -2657 9 D 2011 14657 10 E 2011 1257 11 A 2010 12895 12 B 2010 5381 13 C 2010 -2408 14 D 2010 11849 15 E 2010 517 How do I complete a stacked bar chart in ggplot2 that includes the negative values? Here's the basic chart sequence I'm using: ggplot(income_m, aes(x=Year, y=OperatingIncome, fill=Division)) + geom_bar() + + scale_fill_brewer(type = "seq", palette = 1) This returns an error: Warning message: Stacking not well defined

geom_text how to position the text on bar as I want?

和自甴很熟 提交于 2019-11-26 15:38:19
问题 I would like to adjust the text on the barplot. I tried to adjust hjust/vjust to display as I like it but it seems like it's not working properly. ggplot(data) + geom_bar(aes(name, count, fill = week), stat='identity', position = 'dodge') + geom_text(aes(name,count, label=count),hjust=0.5, vjust=3, size=2, position = position_dodge(width = 1)) + coord_flip() So I would like the numbers to situate on each bar, in the middle, at the right-edge so it's readable without overlapping like the last

ggplot2, geom_bar, dodge, order of bars

不羁岁月 提交于 2019-11-26 14:46:36
问题 I'd like to have ordered bars in dodge geom_bar . Do you know how to deal with it? My code: ttt <- data.frame(typ=rep(c("main", "boks", "cuk"), 2), klaster=rep(c("1", "2"), 3), ile=c(5, 4, 6, 1, 8, 7)) ggplot()+ geom_bar(data=ttt, aes(x=klaster, y=ile, fill=typ), stat="identity", color="black", position="dodge") And example plots to better understand the problem: What I have: What I would like to have: 回答1: One option would be to make a new variable to represent the order the bars should be

ggplot2: Setting geom_bar baseline to 1 instead of zero

社会主义新天地 提交于 2019-11-26 11:34:52
问题 I\'m trying to make a bar graph (with geom_bar) of ratios, and would like to set the x-axis at y=1. Therefore, ratios <1 would be below the axis and ratios >1 would be above the axis. I can do something similar with geom_point: ggplot(data, aes(x=ratio, y=reorder(place,ratio)))+geom_point()+geom_vline(xintercept=1.0)+coord_flip() However geom_bar would be much preferred... Ideally the graph would look something like this: http://i.stack.imgur.com/isdnw.png, except the \"negative\" bars would