0

Could someone help me with a hint to plot these vervet monkey behavioral data? Here are the codes and my expectation.

I want to plot vervet monkeys and I got stuck.

males<-c(21,50,25,12,15,1,5)
females<-c(20,30,22,12,16,46,8)
activities<- c("playing", "grooming", "dancing", "feeding", "mating", "fighting", "eating")

Vervet<-data.frame(activities,females, males)

Vervet |> 
  pivot_longer(females:males, values_to = "Count", names_to = "Gender") |>
  ggplot(mapping = aes(x= activities , y= Count, fill= Gender))+ geom_col(position = "dodge")+
  scale_fill_continuous()+
  coord_flip()+
theme_bw()+
theme(panel.grid = element_blank())

And here are my expectation graph.

enter image description here

3
  • You can click on the above message " enter image description here" to have information on expected grapg. Thank you Commented Dec 29, 2022 at 17:09
  • Remove scale_fill_continuous()+ (and optionally remove coord_flip()+) and you'll end up with a plot that looks almost identical to your expected graph. Commented Dec 29, 2022 at 17:47
  • and then ... + scale_fill_discrete(name = NULL) to remove the legend name. Optionally + labs(x = "Activities") (or up-case the original frame's column name). You can include theme(..., axis.line = element_line(arrow=arrow(type="closed")), panel.border = element_blank()) to change the axis lines. Similarly you can change the axis.ticks as desired. Commented Dec 29, 2022 at 18:21

2 Answers 2

2

I have created more or less what you were looking for. The colors don't match exactly, but you can change that for sure. Maybe also reconsider having the axis labels in place.

library(tidyverse)
males<-c(21,50,25,12,15,1,5)
females<-c(20,30,22,12,16,46,8)
activities<- c("playing", "grooming", "dancing", "feeding", "mating", "fighting", "eating")

Vervet<-data.frame(activities,females, males)

Vervet %>%
  pivot_longer(females:males, values_to = "Count", names_to = "Gender") |>
  ggplot(aes(x= activities , y= Count, fill= Gender, color= Gender))+ 
  geom_col(position = "dodge")+
  scale_color_manual(values = c("lightblue", "khaki"))+
  scale_fill_manual(values = alpha(c("lightblue", "khaki"), 0.5))+
  theme_bw()+
  theme(panel.grid = element_blank(),
        panel.border = element_blank(),
        axis.ticks = element_blank(),
        axis.text = element_blank(),
        axis.line =  element_line(arrow=arrow(type = "closed", 
                                              length= unit(unit(3, "mm")))))+
  labs(x= "Activities")

Created on 2022-12-29 with reprex v2.0.2

Sign up to request clarification or add additional context in comments.

Comments

1

just adapted the colors. the theme part is from @Nick Glättli:

library(tidyr)
library(ggplot2)

Vervet |> 
  pivot_longer(-activities, values_to = "Count", names_to = "Gender") |>
  ggplot(mapping = aes(x= activities , y= Count, fill= Gender, color=Gender))+
  geom_col(position = "dodge")+
  scale_fill_manual(values = c("#d9e8fb", "#ffe6cd"))+
  scale_color_manual(values = c("#899cba", "#c49f49"))+
  theme_bw()+
  theme(panel.grid = element_blank(),
        panel.border = element_blank(),
        axis.ticks = element_blank(),
        axis.text = element_blank(),
        axis.line =  element_line(arrow=arrow(type = "closed", 
                                              length= unit(unit(3, "mm")))))

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.