ggplot with ORR in y axis
0
0
Entering edit mode
1 day ago
Bine ▴ 80

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 • 403 views
ADD COMMENT
1
Entering edit mode

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")
ADD REPLY
0
Entering edit mode

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:

ADD REPLY
1
Entering edit mode

have you tried something like this before the ggplot command?

dplyr::filter( ORR == "Responder" ) %>%
ADD REPLY
1
Entering edit mode

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
ADD REPLY
1
Entering edit mode

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

ADD REPLY
0
Entering edit mode

Yes this column is in metadata.

ADD REPLY

Login before adding your answer.

Traffic: 1367 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6