Vega Lite
mark
How to Create Circle Charts with Vega-Lite

How to Create Circle Charts with Vega-Lite

Ever wondered how to make those neat scatter plots with circles? You're in the right place! Let’s dive into how you can make mesmerizing circle charts using Vega-Lite. We’ll break things down from properties to configurations, peppered with examples to make it a breeze.

What is a Circle Mark in Vega-Lite?

In simple terms, a circle mark is much like the point mark, but always rendered as a circle and filled by default. It’s like a point, but with a circular twist!

Here's the basic structure for a circle mark:

{
  "data": ... ,
  "mark": "circle",
  "encoding": ... ,
  ...
}

Circle Mark Properties

To specify a circle in your visualization, your code will look something like this:

{
  ...
  "mark": {
    "type": "circle",
    ...
  },
  "encoding": ... ,
  ...
}

Your circle mark can include any standard mark properties, plus a special one called size to control the diameter of the circles.

Example: Creating a Scatterplot with Circle Marks

Let’s make things a bit more lively with an example. Imagine you want to plot some data points on a scatter plot, using circles to represent each point.

Here’s a simple scatter plot example:

{
  "data": {
    "url": "data/cars.json"
  },
  "mark": "circle",
  "encoding": {
    "x": {"field": "Horsepower", "type": "quantitative"},
    "y": {"field": "Miles_per_Gallon", "type": "quantitative"},
    "size": {"field": "Weight_in_lbs", "type": "quantitative"}
  }
}

This will plot horsepower on the X-axis, miles per gallon on the Y-axis, and size of the circles based on weight.

Customizing Circle Configurations

Customization is where the magic happens. Your top-level config can include a circle property to set default styles for all circle marks:

{
  ...
  "config": {
    "circle": {
      "size": 100,
      "color": "blue",
      ...
    },
    ...
  }
}

These settings ensure that all your circle marks have a consistent look unless overridden by specific mark encodings.

FAQ

1. What is the difference between circle and point marks?

Great question! Both are used to plot points, but circle marks are always shaped as circles and filled by default, whereas point marks can take various shapes.

2. How can I change the color of my circle marks?

You can customize the color using the color property either at the mark level or in the top-level config:

"mark": {
  "type": "circle",
  "color": "red"
}

3. Can I specify different sizes for each circle?

Absolutely! Use the size encoding channel to adjust sizes based on your data fields:

"size": {
  "field": "SomeDataField",
  "type": "quantitative"
}

Ready to add some pizzazz to your charts? Dive into these properties and examples, and watch your data come to life! Have fun charting with Vega-Lite! 🚀