将轴标签移动到绘图和刻面条之间 [英] Move axis labels in between plot and facet strip

查看:148
本文介绍了将轴标签移动到绘图和刻面条之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将小平面条移动到我的情节的最左侧,以便标签与小节相邻,并且分组小节位于其左侧(请参阅下面的示例)。



我认为这一定要用Grobs来完成,但我对这种操作级别没有经验,并且会很感谢指导。

数据:

 结构(list(dept = structure(c (2L,2L,2L,2L,2L,2L,2L,
1L,1L,1L,1L,5L,5L,5L,5L,5L,5L,5L,5L,5L,5L,2L,2L ,
2L,2L,2L,2L,2L,1L,1L,1L,1L,5L,5L,5L,5L,5L,5L,5L,
5L,5L,5L),标签= c(配送中心服务,IT,
市场营销,商品和库存,运营和沟通
),class =factor),label = c test 25,test 23,test 24,
test 27,test 26,test 28,test 29,test 31,test 33,
test 30,test 32,test 38,test 36,test 37,test 43,
test 34,test 35,test 40 ,测试39,测试42,测试41,
测试25,测试23,测试24,测试27,测试26,测试28 ,
test 29,test 31,test 33,test 30,test 32,test 38,
test 36,test 37测试43,测试34,测试35,测试40,
测试39,测试42,测试41),间隙= c(-0.16,-0.18, - 0.21,
-0.22,-0.27,-0.29, -0.31,-0.31,-0.35,-0.39,-0.42,-0.15,
-0.15,-0.2,-0.21,-0.22,-0.27,-0.29,-0.29,-0.31,-0.36,
-0.16,-0.18,-0.21,-0.22,-0.27,-0.29,-0.31,-0.31,-0.35,
-0.39,-0.42,-0.15,-0.15,-0.2, - 0.21,-0.22,-0.27,-0.29,
-0.29,-0.31,-0.36),section = c(2L,2L,2L,2L,2L,2L,2L,
2L,2L ,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L, (2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L),impeff = 1L,1L,1L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,1L,1L, 1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L),标签= c(有效性,重要性
得分= c(0.77,0.79,0.82,0.8,0.83,0.9,0.91,0.94,0.89,
0.94,0.91,0.82,0.74,0.78,0.81,0.83,0.85,0.82,0.81,
0.8,0.83,0.61,0.61,0.61,0.58,0.56,0.61,0.6,0.63,
0.54,0.55,0.49,0.67,0.59,0.58, ),.Names = c(dept,label,Gap,section,
impeff,分数),row.names = c(23L,24L,25L,26L,27L,28L,
29L,30L,31L,32L,33L,34L,35L,36L,37L,38L,39L,40L, 41L,
42L,43L,66L,67L,68L,69L,70L,71L,72L,73L,74L,75L,76L,
77L,78L,79L,80L,81L,82L,83L, 84L,85L,86L),class =data.frame)

代码:

  curr.plot<  -  ggplot(data = curr.data,aes(x = label,y = score))+ 
geom_bar(aes(fill = impeff),stat =identity,position =dodge,width = .7)+
geom_text(aes(label = percent(score),group = impeff),position = position_dodge (width = .7),vjust = .4,hjust = - 。1)+
facet_grid(dept〜。,switch =y,scales =free_y,space =free)+
$ theme(legend.position =bottom)+
coord_flip()+
guides(fill = guide_legend(reverse = TRUE,title = NULL))+
theme(axis.title .x = element_blank())+
theme(axis.title.y = element_blank())+
theme(axis.text.y = element_text(color =black))+
theme(strip.text.y = element_text(size = 12,color =black))+
scale_y_continuous(labels = percent,limits = c(0,1))

当前输出:



期望的输出(购物):

解决方案

试试:

  +主题(strip.placement =outside)


I am trying to move the facet strip to the far left of my plot, so that the labels sit adjacent to the bars, and the grouping strips sit to their left (see my example below).

I assume this must be done with Grobs, but I have little experience with that level of manipulation and would appreciate guidance.

Data:

structure(list(dept = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 
1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L), .Label = c("Distribution Centre Services", "IT", 
"Marketing", "Merchandise & Inventory", "Operations and Communication"
), class = "factor"), label = c("test 25", "test 23", "test 24", 
"test 27", "test 26", "test 28", "test 29", "test 31", "test 33", 
"test 30", "test 32", "test 38", "test 36", "test 37", "test 43", 
"test 34", "test 35", "test 40", "test 39", "test 42", "test 41", 
"test 25", "test 23", "test 24", "test 27", "test 26", "test 28", 
"test 29", "test 31", "test 33", "test 30", "test 32", "test 38", 
"test 36", "test 37", "test 43", "test 34", "test 35", "test 40", 
"test 39", "test 42", "test 41"), Gap = c(-0.16, -0.18, -0.21, 
-0.22, -0.27, -0.29, -0.31, -0.31, -0.35, -0.39, -0.42, -0.15, 
-0.15, -0.2, -0.21, -0.22, -0.27, -0.29, -0.29, -0.31, -0.36, 
-0.16, -0.18, -0.21, -0.22, -0.27, -0.29, -0.31, -0.31, -0.35, 
-0.39, -0.42, -0.15, -0.15, -0.2, -0.21, -0.22, -0.27, -0.29, 
-0.29, -0.31, -0.36), section = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L), impeff = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L), .Label = c("Effectiveness", "Importance"), class = "factor"), 
    score = c(0.77, 0.79, 0.82, 0.8, 0.83, 0.9, 0.91, 0.94, 0.89, 
    0.94, 0.91, 0.82, 0.74, 0.78, 0.81, 0.83, 0.85, 0.82, 0.81, 
    0.8, 0.83, 0.61, 0.61, 0.61, 0.58, 0.56, 0.61, 0.6, 0.63, 
    0.54, 0.55, 0.49, 0.67, 0.59, 0.58, 0.6, 0.61, 0.58, 0.53, 
    0.52, 0.49, 0.47)), .Names = c("dept", "label", "Gap", "section", 
"impeff", "score"), row.names = c(23L, 24L, 25L, 26L, 27L, 28L, 
29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 
42L, 43L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L), class = "data.frame")

Code:

curr.plot <- ggplot(data = curr.data, aes(x = label, y = score)) + 
    geom_bar(aes(fill = impeff),stat = "identity", position = "dodge",width = .7) +
    geom_text(aes(label=percent(score),group=impeff), position= position_dodge(width=.7),vjust=.4,hjust=-.1) + 
    facet_grid(dept~., switch = "y", scales = "free_y", space = "free") +
    theme(legend.position = "bottom")+
    coord_flip()+
    guides(fill = guide_legend(reverse=TRUE,title=NULL))+
    theme(axis.title.x = element_blank()) +
    theme(axis.title.y = element_blank()) +
    theme(axis.text.y = element_text(colour="black"))+
    theme(strip.text.y = element_text(size = 12, colour = "black"))+
    scale_y_continuous(labels=percent,limits = c(0,1)) 

Current output:

Desired output (shopped):

解决方案

Try:

+ theme(strip.placement = "outside")

这篇关于将轴标签移动到绘图和刻面条之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆