geom-text

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

雨燕双飞 提交于 2019-11-27 11:49:24
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 parts. Edit: The easier solution to get hjust / vjust to behave intelligently is to add the group

Put labels over negative and positive geom_bar

断了今生、忘了曾经 提交于 2019-11-27 06:14:02
问题 I'd like to visualize a data using bar chart and ggplot . I have the data below, when I want to vis this data the text for negative values are not showing below the Bar . dat <- read.table(text = "sample Types Value sample1 A -36 sample2 B 31 sample1 C 15 sample2 D -12 sample1 E 27 sample2 F 16 sample2 G -10 sample2 H 2 sample2 I 6 sample2 J -7 sample2 K -8" , header=TRUE) library(ggplot2) px <- ggplot(data = dat , aes(x = Types , y = Value , Colour = Types )) px + geom_bar(stat = "identity"

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")

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

R: ggplot stacked bar chart with counts on y axis but percentage as label

梦想的初衷 提交于 2019-11-26 11:24:56
问题 I\'m looking for a way to label a stacked bar chart with percentages while the y-axis shows the original count (using ggplot). Here is a MWE for the plot without labels: library(ggplot2) df <- as.data.frame(matrix(nrow = 7, ncol= 3, data = c(\"ID1\", \"ID2\", \"ID3\", \"ID4\", \"ID5\", \"ID6\", \"ID7\", \"north\", \"north\", \"north\", \"north\", \"south\", \"south\", \"south\", \"A\", \"B\", \"B\", \"C\", \"A\", \"A\", \"C\"), byrow = FALSE)) colnames(df) <- c(\"ID\", \"region\", \"species\"