问题描述
我希望在2020年使用Python中的median_area
来绘制下面的数据框disturbance_code
与ggplot
的关系图。
scenario | year | disturbance_code | median_area
------------------------------------------------
Base | 2020 | 1001 | 14264
Base | 2020 | 1002 | 6637
Base | 2020 | 1003 | 18190
Base | 2021 | 1001 | 15000
Base | 2021 | 1002 | 3615
Base | 2021 | 1003 | 3132
我的代码非常简单:
import pandas as pd
import numpy as np
from ggplot import *
data # this is the dataframe above - it comes from elsewhere in my actual code
ggplot(aes(x = 'disturbance_code',y = 'median_area',fill = 'scenario'),data =
data_frame[data_frame['year'] == int(2020)]) +\
theme_bw() +\
geom_bar(stat = 'identity',position = 'dodge') +\
labs(x = 'Severity',y = 'Area burned (ha)')
但是,非常奇怪的是,用geom_bar()
替换geom_line
可以得到:
对于为什么这样做的任何帮助,将不胜感激。
解决方法
相同的问题here。简而言之,答案是将y = 'median_area'
替换为weight = 'median_area'
。