1

Trying to plot a round circle and it gets stretched

library(tidyverse) n = 100 radius = 1 circle <- tibble(x = accumulate(1:(n-1), ~ radius*cos(.y*2*pi/n), .init = radius), y = accumulate(1:(n-1), ~ radius*sin(.y*2*pi/n), .init = 0)) ggplot(circle) + geom_point(aes(x,y), color = "red") 

enter image description here I can use coord_equal()

ggplot(circle) + geom_point(aes(x,y), color = "red") + coord_equal() 

enter image description here But I want to maintain the default (3/4) aspect ratio, specifically when saving I do not want the graphic device to add padding on the sides.

Please advise

1
  • 1
    If you want the circle to be a circle, and maintain a 3/4 aspect ratio, you'll need padding. How exactly do you want the plot to look? Commented Jul 29, 2021 at 8:48

1 Answer 1

3

You can provide the limits argument of the position scales as a function that takes the natural limits of the data as the argument. This works with a fixed aspect ratio, but doesn't automatically adapt to fit the available size in the graphics device.

library(tidyverse) n = 100 radius = 1 circle <- tibble(x = accumulate(1:(n-1), ~ radius*cos(.y*2*pi/n), .init = radius), y = accumulate(1:(n-1), ~ radius*sin(.y*2*pi/n), .init = 0)) asp <- 3 / 4 ggplot(circle) + geom_point(aes(x,y), color = "red") + scale_x_continuous( limits = function(x) { mid <- mean(x) mid + c(-1, 1) * (1/asp) * 0.5 * diff(x) } ) + coord_equal() 

Created on 2021-07-29 by the reprex package (v1.0.0)

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.