如何使用 ggplot 在 R 中的组合堆积条形图和散点图中按总计进行排序

问题描述 投票:0回答:1

如何在此图表中按

Fuel
(即标记为黑点的净值)对
value_out.net
进行排序? 请看图和下面的代码:

The plot. I want to sort Fuel sothat the totals, or net values, are sorted in ascending or descending order.

fuels_out_plot_w_tot_order <- ggplot() +
  geom_bar(data = all_fuels, aes(x = Fuel, y = value_out, fill = stage_emission), stat = "identity") +
  geom_point(data = all_fuels, aes(x = Fuel, y = value_out.net), size = 1) +
  scale_y_continuous("g CO2e/kWh", 
                     sec.axis = sec_axis(~ . / conv_mj_kwh, name = "g CO2e/MJ")) +
  theme(legend.title = element_blank()) +
  ggtitle("Well-to-wheel emissions (powertrain efficiency considered)") +
  coord_flip(); fuels_out_plot_w_tot_order

我尝试了

reorder()
,但我无法让它工作。

r ggplot2 geom-point
1个回答
0
投票

所有燃料 <- all_fuels %>% 变异(燃料 = forcats::fct_reorder(燃料,value_out.net))

© www.soinside.com 2019 - 2024. All rights reserved.