geom-bar

Color/fill bars in geom_col based on another variable?

旧巷老猫 提交于 2020-06-17 04:19:46
问题 I have an uncolored geom_col and would like it to display information about another (continuous) variable by displaying different shades of color in the bars. Example Starting with a geom_col library(dplyr) library(ggplot2) set.seed(124) iris[sample(1:150, 50), ] %>% group_by(Species) %>% summarise(n=n()) %>% ggplot(aes(Species, n)) + geom_col() Suppose we want to color the bars according to how low/high mean(Sepal.Width) in each grouping (note: I don't know if there's a way to provide

Reorder Overlaid Bars in Plot so Longer Bars are in back -R

允我心安 提交于 2020-05-30 08:29:51
问题 I have a barplot that I want to overlay. The issue is that longer bars are covering shorter bars. There's a function in excel that allows for longer bars to be pushed to the back, and shorter bars brought to the forefront. How can I do that in R? My code is below: ggplot(df2) +geom_bar(aes(x = id, y = `Feb-20`), position = "identity",stat="identity", fill = 'green') + geom_bar(aes(x = id, y = `Mar-20`), position = "identity", stat="identity",fill = 'navy') + geom_bar(aes(x = id, y = `Apr-20`)

Reorder Overlaid Bars in Plot so Longer Bars are in back -R

吃可爱长大的小学妹 提交于 2020-05-30 08:29:26
问题 I have a barplot that I want to overlay. The issue is that longer bars are covering shorter bars. There's a function in excel that allows for longer bars to be pushed to the back, and shorter bars brought to the forefront. How can I do that in R? My code is below: ggplot(df2) +geom_bar(aes(x = id, y = `Feb-20`), position = "identity",stat="identity", fill = 'green') + geom_bar(aes(x = id, y = `Mar-20`), position = "identity", stat="identity",fill = 'navy') + geom_bar(aes(x = id, y = `Apr-20`)

Alpha aesthetic shows arrow's skeleton instead of plain shape - how to prevent it?

谁都会走 提交于 2020-05-12 11:43:59
问题 I'm aiming at building a bar plot with arrows at the end of bars. I went for geom_segment with arrow defined. I want to map one column onto transparency, but the alpha aesthetic doesn't seem to work fine with arrow object. Here's the code snippet: tibble(y = c(10, 20, 30), n = c(300, 100, 200), transparency = c(10, 2, 4)) %>% ggplot() + geom_segment(aes(x = 0, xend = n, y = y, yend = y, alpha = transparency), colour = 'red', size = 10, arrow = arrow(length = unit(1.5, 'cm'), type = 'closed'))

Matching axis.text labels to colors contained in data frame variable in ggplot

若如初见. 提交于 2020-04-30 07:39:36
问题 I would like to create a stacked bar chart where my axis.text takes it's color values from a variable in the data frame that also provides the bar's fill color. This is very important because the consumers of the final visuals will be viewing a series of these bar charts so I need to make sure the colors are consistent for each product type even though the Amount values (and thus the order) will vary. The below is the closest I can get. # My data sample df <- data.frame(x=1:4, Type = c(

R geom_bar and facet_grid labels on top of bars

随声附和 提交于 2020-03-25 07:33:17
问题 I am trying to make this graph look better, and I'm stuck with the labels (the numbers in this case). How can I make them to show on the top of their correspondent bar? Notice it is a facet_grid. I have the following code and the output: ggplot(articles_europaoccidental_sex_count_unique_group, aes(Country, percentage)) + geom_bar(stat = "identity", position = "dodge", aes(fill=Gender)) + facet_grid(~Propuesta) + geom_text(aes(label = round(percentage, 2)), position = position_dodge(width = 0

How to create a geom_bar of two tables using ggplot

。_饼干妹妹 提交于 2020-01-15 05:15:06
问题 I have a problem creating a geom_bar two tables using ggplot. I have two tables: 1) characteristic men_weekly_earnings 1 16 to 24 years 493 2 16 to 19 years 392 3 20 to 24 years 507 4 25 to 34 years 755 5 35 to 44 years 964 6 45 to 54 years 1011 7 55 to 64 years 1021 8 65 years and older 942 2) characteristic women_weekly_earnings 1 16 to 24 years 451 2 16 to 19 years 357 3 20 to 24 years 468 4 25 to 34 years 679 5 35 to 44 years 781 6 45 to 54 years 780 7 55 to 64 years 780 8 65 years and