![](/img/trans.png)
[英]r ggplot2 facet_grid how to add space between the top of the chart and the border
[英]Add space between specific facets in ggplot2 (facet_grid)
我已經能夠在所有方面之間添加垂直空間( 改變方面之間的水平間距(ggplot2) )但是在指定的方面之間只能添加一個空格?
這是一個基於我的真實數據的例子(在真實的情節中,我有疊條):
mydf<-data.frame(year = rep(c(2016,2016,2016,2016,2016,2016,2017,2017,2017,2017,2017,2017),times = 2),
Area = rep(c('here','there'),times = 12),
yearArea = rep(c('here.2016','here.2017', 'there.2016','there.2017'), times = 12),
treatment = rep(c('control','control','control','treat', 'treat','treat'), times = 4),
response = rep(c('a','b','c','d'), times = 6),
count = rep(c(23,15,30,20), times = 6))
mycolour<-c("#999999", "#0072B2", "#009E73","#000000")
返回圖:
#default facet spacing
example<-ggplot(data=mydf, aes(x=treatment, y=count, fill=response)) +
geom_bar(stat="identity", width = 0.5) +
scale_fill_manual(values = mycolour, name = "Response") +
labs (y = "Count") +
facet_grid(~yearArea) +
theme_bw()
example
#spacing between each facet
spacedex<-example + theme(panel.spacing.x=unit(2, "lines"))
spacedex
如何限制僅在第二和第三方面之間添加空間? (在這里.2017和那里.2016)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.