R 几何坐标值顺序错误
我是新来R的。我对下面R 几何坐标值顺序错误,r,ggplot2,position,geom-text,geom-col,R,Ggplot2,Position,Geom Text,Geom Col,我是新来R的。我对下面geom\u col图表中geom\u文本元素的排序有问题 我相信这与position=position\u dodge2(preserve=“single”)行有关,但我不确定 样本代码和输出附件。如您所见,标签错误-e和b以及a和d 一个眼睛更敏锐的人(可能头脑更敏锐的人)能看到问题是什么吗 库(ggplot2) 图书馆(stringr) 数据干得好。也许您可以尝试在geom\u text的美学中添加group=Importance。也就是说,要“明确定义分组结构”,
geom\u col
图表中geom\u文本
元素的排序有问题
我相信这与position=position\u dodge2(preserve=“single”)
行有关,但我不确定
样本代码和输出附件。如您所见,标签错误-e
和b
以及a
和d
一个眼睛更敏锐的人(可能头脑更敏锐的人)能看到问题是什么吗
库(ggplot2)
图书馆(stringr)
数据干得好。也许您可以尝试在geom\u text
的美学中添加group=Importance
。也就是说,要“明确定义分组结构”,请参阅。还有一个相关案例
ggplot(data, aes(x = Importance, y = Current.Capability, fill=Function)) +
geom_col(position = position_dodge2(preserve = "single"), width = width) +
facet_grid(~Importance, scales = "free_x", space = "free_x") +
geom_text(
aes(
label = stringr::str_wrap(Item, 50),
group = Importance), # explicitly define the grouping structure
lineheight = 0.7,
angle=90,
size = 5,
hjust=0,
vjust=0.5,
y = 0.5,
position = position_dodge2(preserve = "single", width = position.width)) +
theme(axis.text.x = element_blank(), axis.ticks = element_blank()) +
theme(legend.position="bottom")+
scale_y_discrete(limits = c("Undeveloped", "Basic", "Advanced", "World class")) +
xlab("Importance") + ylab("Current Capability")
谢谢!这个问题确实与分组有关。我通过在aes中加入geom_col解决了这个问题,但是,不是geom_文本。但你让我走上了正确的道路!嗨@BrevanD'Angelo!酷!您还可以直接在ggplot
的aes
中包括group=Importance
,如ggplot(data,aes(…,group=Importance))
也可以使用。
ggplot(data, aes(x = Importance, y = Current.Capability, fill=Function)) +
geom_col(position = position_dodge2(preserve = "single"), width = width) +
facet_grid(~Importance, scales = "free_x", space = "free_x") +
geom_text(
aes(
label = stringr::str_wrap(Item, 50),
group = Importance), # explicitly define the grouping structure
lineheight = 0.7,
angle=90,
size = 5,
hjust=0,
vjust=0.5,
y = 0.5,
position = position_dodge2(preserve = "single", width = position.width)) +
theme(axis.text.x = element_blank(), axis.ticks = element_blank()) +
theme(legend.position="bottom")+
scale_y_discrete(limits = c("Undeveloped", "Basic", "Advanced", "World class")) +
xlab("Importance") + ylab("Current Capability")