2

Here is my code...I want to change the x and y labels and the legend. Also, does anyone know how to stack the two variables on one another instead of side by side?

install.packages("dplyr")
install.packages("tidyr")
install.packages("ggplot2")

library("dplyr")
library("tidyr")
library("ggplot2")


dat <- data.frame(
Hunter = c(40, 25, 11,9,146,6,6,4,4,53),
Nonhunter = c(819, 510,219,195,1,132,117,89,85,1),
Source = as.factor(c("NC", "LT", "WCS", "WWF", "DU", "TCF", "NRDC","NWF","NAS","RMEF"
                     ))
)

dat_long <- dat %>%
gather("Stat", "Value", -Source)
 
dat_long

ggplot(dat_long, aes(x = Source, y = Value, fill = Stat)) +
geom_col(position = "dodge")

Here is a picture of my graph:

enter image description here

lovalery
  • 4,524
  • 3
  • 14
  • 28
  • This [link](https://stackoverflow.com/a/20370009/5874001) will be of some use I think. – InfiniteFlash Nov 30 '19 at 22:45
  • 1
    How to build a "stacked bar chart" has been addressed many times in SO Q&A's. You should edit your answer to indicated what sort of searching you have done and what you have found and why it doesn't address your particular needs. As of today I get 557 hits to a search with those terms and "[ggplot]": https://stackoverflow.com/search?q=%5Br%5D+%5Bggplot2%5D+stacked+bar+chart+ Also: multi-part questions are deprecated in SO. Please read [ask] more thoroughly than it appears you have so far. – IRTFM Dec 01 '19 at 00:09

0 Answers0