'How to add point size to a Gadfly (Julia) scatter plot based on a variable
I am trying to reproduce this Seaborn plot using Gadfly.
The code I have so far is:
using CSV, DataFrames, Gadfly
download("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/mpg.csv", "mpg.csv");
mpg = DataFrame(CSV.File("mpg.csv"));
p = plot(
mpg,
x = :horsepower,
y = :mpg,
color = :origin,
#size = :weight,
alpha = [0.5],
Geom.point,
Theme(background_color = "white"),
)
How do I add the size of the circles to match the car weight and add this as a second legend?
Solution 1:[1]
See detailed answer by Evan Fields on Discourse:
p = plot(
mpg,
x = :horsepower,
y = :mpg,
color = :origin,
size = :weight,
alpha = [0.5],
Geom.point,
Theme(background_color = "white"),
Scale.size_area(maxvalue=maximum(mpg.weight)),
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


