Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R position_stack不适用于镶嵌面_包裹_R_Ggplot2 - Fatal编程技术网

R position_stack不适用于镶嵌面_包裹

R position_stack不适用于镶嵌面_包裹,r,ggplot2,R,Ggplot2,我正在用图表绘制一些股票。我想把标签放在每个分数的中间,但是即使当我使用 PosithyStase时,它只给了我第一个图(阿尔伯塔)所需的标签,但其余的不是。 df$label我认为问题在于geom_text层不知道要堆叠什么,特别是不知道堆叠的顺序。这是因为Fuel列确定了条形图的堆叠顺序,但对于geom_text层,根本没有映射 最简单的修复方法是将美学贴图移动到ggplot()而不是单个图层中。这样,它将被后续层继承(也避免了每个层中的x和y美学的重复)。借助于ggplot的魔力,即使g

我正在用图表绘制一些股票。我想把标签放在每个分数的中间,但是即使当我使用<代码> PosithyStase时,它只给了我第一个图(阿尔伯塔)所需的标签,但其余的不是。


df$label我认为问题在于
geom_text
层不知道要堆叠什么,特别是不知道堆叠的顺序。这是因为
Fuel
列确定了条形图的堆叠顺序,但对于
geom_text
层,根本没有映射

最简单的修复方法是将美学贴图移动到
ggplot()
而不是单个图层中。这样,它将被后续层继承(也避免了每个层中的
x
y
美学的重复)。借助于
ggplot
的魔力,即使
geom_text
不使用
fill
映射进行填充,它仍然知道根据该位置的美学进行分组/排序

我已经做了更改,将文本层的
position\u stack
更改为
position\u fill
,并将
geom\u bar(stat=“identity”)
替换为
geom\u col
,这是该习惯用法的首选方法

ggplot(data = df, aes(factor(1), y = fuel.share, fill = Fuel)) +
  geom_col(position = "fill") +
  geom_text(aes(label = label)
  , size =2
  ,position = position_fill(vjust = 0.5)) +
  coord_polar(theta = "y") +
  facet_wrap(prov ~ .) +
  scale_x_discrete(name = "", breaks = NULL) +
  scale_y_continuous(name = "", breaks = NULL) 

我认为问题在于
geom_text
层不太知道要堆叠什么,特别是不知道堆叠的顺序。这是因为
Fuel
列确定了条形图的堆叠顺序,但对于
geom_text
层,根本没有映射

最简单的修复方法是将美学贴图移动到
ggplot()
而不是单个图层中。这样,它将被后续层继承(也避免了每个层中的
x
y
美学的重复)。借助于
ggplot
的魔力,即使
geom_text
不使用
fill
映射进行填充,它仍然知道根据该位置的美学进行分组/排序

我已经做了更改,将文本层的
position\u stack
更改为
position\u fill
,并将
geom\u bar(stat=“identity”)
替换为
geom\u col
,这是该习惯用法的首选方法

ggplot(data = df, aes(factor(1), y = fuel.share, fill = Fuel)) +
  geom_col(position = "fill") +
  geom_text(aes(label = label)
  , size =2
  ,position = position_fill(vjust = 0.5)) +
  coord_polar(theta = "y") +
  facet_wrap(prov ~ .) +
  scale_x_discrete(name = "", breaks = NULL) +
  scale_y_continuous(name = "", breaks = NULL) 

您的
dput
似乎过早地被切断,它以
prov=c(“阿尔伯塔”、“安大略”、“魁北克”、“萨斯喀彻温省”)结束,
无法在没有数据的情况下进行测试,但我很惊讶您使用
position=“fill”
作为条形图,使用
position=position\u stack()
作为文本标签。看起来你希望它们是一样的。请尝试
position=position\u fill(vjust=0.5)
。对于数据集,我已经更正了。即使使用
position=position\u fill(vjust=0.5)
,我仍然得到相同的结果。您的
dput
似乎过早中断,它以
prov=c(“阿尔伯塔”、“安大略”、“魁北克”、“萨斯喀彻温”),
无法在没有数据的情况下进行测试,但我很惊讶您使用
position=“fill”
用于条形图,而
position=position\u stack()
用于文本标签。看起来你希望它们是一样的。请尝试
position=position\u fill(vjust=0.5)
。对于数据集,我已经更正了。即使使用
position=position\u fill(vjust=0.5)
,我仍然得到相同的结果。
ggplot(data = df, aes(factor(1), y = fuel.share, fill = Fuel)) +
  geom_col(position = "fill") +
  geom_text(aes(label = label)
  , size =2
  ,position = position_fill(vjust = 0.5)) +
  coord_polar(theta = "y") +
  facet_wrap(prov ~ .) +
  scale_x_discrete(name = "", breaks = NULL) +
  scale_y_continuous(name = "", breaks = NULL)