Change plot size

Hi everyone,

I have the following code

ggplot(drop_na(penguins)) + 
    mapping = 
      aes(species, body_mass_g, fill = species),
      outlier.shape = 21, # A number 0:25 , NA will hide the outliers
      outlier.size = 3,
      outlier.fill = 'red'
  ) + 
  facet_wrap(sex ~ ., scales = 'free_x', ncol = 1)

which shows the following plot

As you can see, the plot is quite compressed. so how could I customize the height, width and the increments on the Y-axis .

Thanks :slightly_smiling_face: :slightly_smiling_face:

It depends on what you want to do with the plot. Most often, I'm exporting as a png to use elsewhere. So I mostly use ggsave("mygraph.png", height = , width =, units = "cm", bg = "white") and adjust height and width to suit the plot. Often the text and labelling sorts itself out in this case.

1 Like

Thanks for your reply

Ok this is for saving the plot but If I wanna change the dimensions of the plot that appears in output in the markdown itself. How could I do it?

You can change the plot size in markdown for the whole file, or in the heading for each block. Width and aspect ratio are the things to look for, I believe.

Ok a guy on Slack gave me the solution and it worked
"set the image size in the arguments to the code chunk (look for the little gear just to the left of the green triangle
and you can use scale_y_continuous() to set the breaks= and labels= arguments."

This topic was automatically closed 7 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.