how to transform the geom_boxplot legend angle

i want to rotate the legend box
so it can match with the plot

library(tidyverse)
ggplot + geom_boxplot(data = df , aes = (x = xx, y = yy, color = cc))

in this plot

the legend direction is not compatible with plot content.

i want to rotate the legend with 90.

maybe i show ed some new content to illustrate this question.

pig 1

we can see the legend boxplot is one situation.

now suppose i want to get the pig 2

look at the legend. it is reversed. and i want to know how i can get that place. and at the same time, i want to make text(just like am,0,1) not to rotate, just rotate the icon.

Thank you for your reply.

Try this:

... +
theme(legend.direction="horizontal")

Maybe also legend.position="bottom", can be useful

1 Like

i think i have not illustrate clearly what i want to get.
i have edited the post agian.
and thank you for your help.
if you have any idea, please post it more and thank you very much.

The default legend is vertical with the letters to the right. What would you like to have the letters on top of the color? in this case I'm not sure how to get the result

mpg %>% 
  ggplot(aes(x = cyl, y = hwy, fill = fl)) +
  geom_boxplot() +
  labs(fill = NULL) +
  theme_classic()

1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.