I'm looking to plot of the below dataframe median_area
against disturbance_code
in year 2020 using ggplot
in Python.
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
My code is, very simply:
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)')
This gives the following plot:
However, what's very strange is that a simple replacement of geom_bar()
with geom_line
gives:
Any help on why this is would be appreciated.
Identical question here. The answer, in short, is to replace y = 'median_area'
with weight = 'median_area'
.