简体   繁体   English

如何基于变量将点大小添加到 Gadfly (Julia) 散点图

[英]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.我正在尝试使用 Gadfly 重现这个Seaborn 情节。

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?如何添加圆圈的大小以匹配汽车weight并将其添加为第二个图例?

在此处输入图像描述

See detailed answer by Evan Fields on Discourse :请参阅 Evan Fields 在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)),
)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM