admin管理员组文章数量:1287650
I am trying to create a simple radial/polar plot in R ggplot2 using coord_radial(), which is similar to coord_polar but with more options. Below is an example plot with data:
library(ggplot2)
plot_data <- data.frame('xval' = seq(1, 100),
'yval' = seq(100, 1))
ggplot(plot_data, aes(x = xval, y = yval))+
geom_col()+
scale_y_continuous(expand = c(0, 0))+
coord_radial(theta = 'x', start = 0)+
theme_void()+
theme(panel.border = element_rect(fill = NA),
axis.line.x = element_line())
Which produces a plot that looks as follows:
What I want to do is remove the spacing between the inner circle (defined by axis.line.x) and the outer rectangle (defined by panel.border). In other words, I need the circle to be touching the outer panel.border. I have tried manipulating the expand parameters in scale_x/y_continuous and adjusting the theme() but to no avail. The "expand" and "clip" parameters in coord_radial() also had no effect.
The end goal is that I want to be able to save the plot as an image where the borders are defined by the circle limits and not by the outer rectangle. If there is another way of doing this besides removing the spacing, that should work too.
Thank you in advance!
I am trying to create a simple radial/polar plot in R ggplot2 using coord_radial(), which is similar to coord_polar but with more options. Below is an example plot with data:
library(ggplot2)
plot_data <- data.frame('xval' = seq(1, 100),
'yval' = seq(100, 1))
ggplot(plot_data, aes(x = xval, y = yval))+
geom_col()+
scale_y_continuous(expand = c(0, 0))+
coord_radial(theta = 'x', start = 0)+
theme_void()+
theme(panel.border = element_rect(fill = NA),
axis.line.x = element_line())
Which produces a plot that looks as follows:
What I want to do is remove the spacing between the inner circle (defined by axis.line.x) and the outer rectangle (defined by panel.border). In other words, I need the circle to be touching the outer panel.border. I have tried manipulating the expand parameters in scale_x/y_continuous and adjusting the theme() but to no avail. The "expand" and "clip" parameters in coord_radial() also had no effect.
The end goal is that I want to be able to save the plot as an image where the borders are defined by the circle limits and not by the outer rectangle. If there is another way of doing this besides removing the spacing, that should work too.
Thank you in advance!
Share Improve this question asked Feb 23 at 17:55 AmpAmp 716 bronze badges1 Answer
Reset to default 4Following this comment by @teunbrand on a related GH issue you can get rid of the extra white space by adding
ggproto(
NULL, coord_radial("y", start=0, expand = FALSE),
inner_radius = c(0, 0.5)
)
to your plot.
library(ggplot2)
plot_data <- data.frame(
"xval" = seq(1, 100),
"yval" = seq(100, 1)
)
ggplot(plot_data, aes(x = xval, y = yval)) +
geom_col() +
theme_void() +
theme(
panel.border = element_rect(fill = NA, color = "red"),
axis.line.x = element_line(color = "green")
) +
ggproto(
NULL, coord_radial("x", start = 0, expand = FALSE),
inner_radius = c(0, 0.5)
)
本文标签: Remove whitespace between axisline and panelborder in geomradial with R ggplot2Stack Overflow
版权声明:本文标题:Remove whitespace between axis.line and panel.border in geom_radial with R ggplot2 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741308374a2371505.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论