Alan Alves
Alan Alves

Reputation: 71

Plotnine printing point geometry legend as polygon

In my map I have multiple layers. One being points and others being polygons. I want show proper legend (points to show points, polygons to show polygons), whatever way I try I cannot get it to wok.

    # Precipitation map
precip_station_map = (
    ggplot(precip_stations_clipped)
    + geom_map(
        mapping=aes(geometry='geometry'),
        color = 'red'
    )
    + geom_map(
        data=upper_hudson_basin_10km_buffer,
        mapping=aes(geometry='geometry', color='"10km buffer"'),
        inherit_aes=False,
        fill=None
    )
    + geom_map(
        data=upper_hudson_basin_30km_buffer,
        mapping=aes(geometry='geometry', color='"30km buffer"'),
        inherit_aes=False,
        fill=None
    )
    + geom_map(
        data=upper_hudson_basin.to_crs(precip_stations_clipped.crs),
        mapping=aes(geometry='geometry', color='"Upper Hudson Basin"'),
        inherit_aes=False,
        fill=None
    )
    + labs(title='Precipitation Map')
    + scale_color_manual(
        name='Buffer Distance:',
        values={
            '10km buffer': 'royalblue',
            '30km buffer': 'orange',
            'Upper Hudson Basin': 'black'
            }
    )
    + theme_minimal()
    + theme(
        legend_title=element_text(size=10),
        legend_text=element_text(size=8),
        legend_position='bottom'
    )
)
precip_station_map.draw()

enter image description here

I tried the following, but it is still not working. In the figure below, I want the precipitation station to appear in the legend as a dot, not a polygon.

geom_merged = pd.concat(
    [
        #precip_stations_clipped[['geometry']].assign(LAYER='Preciptation Station'),
        upper_hudson_basin.to_crs(precip_stations_clipped.crs)[['geometry']].assign(LAYER='Upper Hudson'),
        upper_hudson_basin_10km_buffer[['geometry']].assign(LAYER='10km buffer'),
        upper_hudson_basin_30km_buffer[['geometry']].assign(LAYER='30km buffer')
    ]
)

precip_station_map2 = (
    ggplot(geom_merged)
    + geom_map(
        mapping=aes(geometry='geometry', color = 'LAYER'),
        fill = None
    )
    + geom_map(
        data = precip_stations_clipped[['geometry']].assign(LAYER='Preciptation Station'),
        mapping=aes(gemetry='geometry', color='LAYER')
    )

)

enter image description here

Upvotes: 0

Views: 17

Answers (0)

Related Questions