How to add 2 values as Cases (Percent%) in bar chart?

43 просмотра
Перейти к первому непрочитанному сообщению

Orapun Arjkumpa

не прочитано,
30 сент. 2020 г., 13:23:4230.09.2020
– ggplot2
This is the data;
N <- read.table(header=T, text="
                Type Status Cases Percent
                EEHV1A Died 42 70.4
                EEHV1B Died 5 83.3
                EEHV4 Died 11 31.4
                E1&E4 Died 2 100.0
                EEHV1A Survived 14 30.0
                EEHV1B Survived 1 16.7
                EEHV4 Survived 16 68.6
                E1&E4 Survived 0 0.0
                ")
I run this script;ggplot(N, aes(fill=Status, Type, Cases))+
  geom_bar(stat="identity", position="dodge") + 
  scale_x_discrete (limits= c("EEHV1A", "EEHV1B", "EEHV4", "E1&E4")) +
  geom_text(aes(label = Cases, y = Cases + 0.05), position = position_dodge(0.9), vjust = -0.5, color="black") +
  geom_text(aes(label = Percent, y = Percent + 0.05), position = position_dodge(0.9), vjust = -0.5, color="black")
I would like to have a label as Cases (Percent%) so how should I do?

Thank you 😊 

Lorenzo Crippa

не прочитано,
30 сент. 2020 г., 13:36:1430.09.2020
– Orapun Arjkumpa, ggplot2
Hi,

Is this more or less what you wanted to obtain?

ggplot(N, aes(fill=Status, Type, Cases))+
  geom_bar(stat="identity", position = position_dodge(width = 0.9)) + 
  scale_x_discrete (limits= c("EEHV1A", "EEHV1B", "EEHV4", "E1&E4")) +
  geom_text(aes(label = paste0(Cases, " ", "(", round(Percent, digits = 0), "%)")), 
            vjust = -.5, size = 3.4, position = position_dodge(width = 0.9))

Best,
Lorenzo

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ggplot2/3a299001-9326-49c2-87e8-2bf963609207n%40googlegroups.com.

Ответить всем
Отправить сообщение автору
Переслать
0 новых сообщений