-1

enter image description here

I have got this dataset. I am trying to do a stacking bar graph with proportions using ggplot for this data:

enter image description here

I am not really sure how to manipulate it into tables first! I know, I just started learning R, two weeks ago and I'm kind of stuck. I made a similar graph before. I attached it here.

halfer
  • 19,824
  • 17
  • 99
  • 186
AA AA
  • 1
  • Hi, @AAAA. Welcome to StackOverflow! Please include some example code so that we can see what you've tried and help correct any errors. – shirewoman2 Mar 30 '20 at 04:38

1 Answers1

0

I'm not sure if I got your question right, but I'll try to answer it. I see that this is your first question in Stack Overflow, so I'd advise you to post a minimal reproducible example on your next question.

1) "I am not really sure how to manipulate it into tables first!"

Copy the data into an excel file, save it as csv and import into R with base R command.

df <- read.csv('your_data.csv')

2) " do a stacking bar graph with proportions"

Your problem is very similar to the one mentioned in this question. Make sure to check it out, but I've already adapted the code below, see if it works.

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

    df <- read.csv('your_data.csv')

    # Add an id variable for the filled regions and reshape
    dfm <- df %>% 
      mutate(Domain = factor(row_number()) %>% 
      gather(variable, value, -Domain)

    ggplot(dfm, aes(x = variable, y = value, fill = Domain)) + 
        geom_bar(position = "fill",stat = "identity") +
        # or:
        # geom_bar(position = position_fill(), stat = "identity"
    scale_y_continuous(labels = scales::percent_format())
大朱雀
  • 337
  • 3
  • 12