Home > Enterprise >  where to pass argument to radiate margin labels of a polar heatmap
where to pass argument to radiate margin labels of a polar heatmap

Time:09-14

This question builds on from here: enter image description here

Which is great, but I would like the labels on the rim of the figure to radiate out (or be tangent, for that matter). So, I wrote the angles as:

ang <- 1:30/31.5*360

However, I can not see where to pass this argument. Looking around, it would normally be in the aes function, but there the labels are for the y-axis in the figure (before being changed to the polar coordinates), and what I am wanting rotated should be in the x-axis. So, how do I do this? Thanks for any suggestions!

CodePudding user response:

You can add this in the axis.text.x = element_text() :

ang <- 90 - (1:30/31.5*360)

dff %>%
  mutate(Site = seq(nrow(.))) %>%
  pivot_longer(-Site, names_to = 'Species', values_to = 'Abundance') %>%
  mutate(yval = match(Species, colnames(dff))) %>%
  ggplot(aes(Site, yval, fill = Abundance))  
  geom_tile(color = "black")  
  geom_text(aes(label = colnames(dff)), hjust = 1.1, size = 3,
            data = data.frame(Site = 31.5, yval = 1:15, Abundance = 1))  
  coord_polar()  
  scale_y_continuous(limits = c(-5, 15.5))  
  scale_x_continuous(limits = c(0.5, 31.5), breaks = 1:30, labels = names.d,
                     name = 'Breeding site')  
  scale_fill_gradientn(colors = colorRampPalette(RColorBrewer::brewer.pal(name = "YlOrRd", n = 9))(25), values = 0:1, labels = scales::percent) 
  theme_void(base_size = 16)  
  theme(axis.text.x = element_text(size = 12, angle = ang),
        axis.title.x = element_text())

enter image description here

  • Related