This is a test version of Biostars. For the public version, visit https://www.biostars.org.
ggplot with ORR in y axis

Good afternoon,

I was wondering if anyone could guide me here: I would like to change my current plot in a way that I get the overall response rate (percentage of Responders) in the y-axis. I am not interested to show the percentage of Non-responder. Then I would also remove the current legend.

enter image description here

Current code:

p<-metadata %>%
    dplyr::count(triplet_douplet, ORR) %>% 
    dplyr::group_by(triplet_douplet) %>%
    dplyr::mutate(prop = n / sum(n)) %>%
  ggplot(aes(x =triplet_douplet, y = prop, fill =ORR)) +
  geom_col(position = position_dodge()) +
  geom_text(aes(label = round(100 * prop)),
            position = position_dodge(.9), vjust = -.2
  )

I have been trying different attempts but no success yet. Any ideas?

ggplot

If i understand correctly, why not just change the mutate bit to:

dplyr::mutate(prop = 100 * n / sum(n))

As well as removing the 100 from the geom_text command.

You can also remove the legend by using:

theme(legend.position = "none")

Thanks for your reply. But this is not what I meant. My aim is to get something like this:

enter image description here

I am not interested in the percentage of the non-responder, just show the percentage of the responder:

have you tried something like this before the ggplot command?

dplyr::filter( ORR == "Responder" ) %>%

Great, yes like this it is working! Thanks so much.

Sharing the code in case someone is interested:

metadata %>%
dplyr::count(triplet_douplet, ORR) %>% 
 dplyr::group_by(triplet_douplet) %>%
  dplyr::mutate(prop = n / sum(n)) %>%
  dplyr::filter( ORR == "Responder" ) %>%
  ggplot(aes(x =triplet_douplet, y = prop, fill =ORR)) +
  geom_col(position = position_dodge()) +
  geom_text(aes(label = round(100 * prop)),
            position = position_dodge(.9), vjust = -.2
  )

I have one final question: In case I want to replace "ORR" in fill with "height" it gives me this error, even so "height" is a variable in metadata. Maybe it happens because I filter and it cannot longer recognise it?!

Thanks again!

Error in `geom_col()`:
! Problem while computing aesthetics.
Error occurred in the 1st layer.
Caused by error in `FUN()`:
! object 'height' not found

Hard to say without looking at the data and the ggplot command, are you sure this is column is around?

Ok got it. Need to add "height" here:

dplyr::count(triplet_douplet,height, ORR) %>% 

0 answers

No answers yet.

Log in to answer this question.