Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

changing colors of geom_col ggplot2 to show categorical variable at 3 sites

$
0
0

Long time fan of this site, first time user though. Been searching for a similar/working result for this question. I am trying to show the PROPORTION that each level of a 2 level factor appear at three locations. All in a side by side bar chart in ggplot.

Here is the code I've been using to (try) to create the chart. The result has been two charts: one using geom_bar and geom_col, respectively. What I'd like is essentially a combination of the two. The first, but with the colors and Y axis of the second.

Thank you!

    ggplot(df,aes(x = Stream,fill = death)) + 
    geom_bar(position = "dodge")+
    scale_fill_manual(values = c(rep(c("gray45", "gray75"))))+
    labs(fill="Time of Death") 

enter image description here

    death_stream <-df %>%
    group_by(Stream,Tree_Death)%>%
    summarise (n = n()) %>%
    mutate(rel.freq = paste0(round(100 * n/sum(n), 0), "%"))


    death_stream %>% 
    ggplot(aes(x = Stream,y = rel.freq)) + 
    geom_col(position = "dodge",fill = "grey50", colour = "black")+
    labs(fill="Time of Death")

enter image description here


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>