- Learning Jupyter 5
- Dan Toomey
- 228字
- 2025-04-04 16:20:21
R 3D scatterplot in Jupyter
The R lattice package has a Cloud function that will produce 3D scatterplots.
The script we will use is as follows:
# make sure lattice package is installed install.packages("lattice") # in a standalone R script you would have a command to download the lattice library - this is not needed in Jupyter library("lattice") # use the automobile data from ics.edu mydata <- read.table("http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data") # define more meaningful column names for the display colnames(mydata) <- c("mpg", "cylinders", "displacement", "horsepower", "weight", "acceleration", "model.year", "origin", "car.name") # 3-D plot with number of cylinders on x axis, weight of the vehicle on the y axis and miles per gallon on the z axis. cloud(mpg~cylinders*weight, data=mydata)
Prior to running it, we will have something such as this:

Notice that we are using markup type cells for comments about the script steps. They are also denoted without a script line number in the left-hand column.
If you are copying R script into a Jupyter window, you may run across an issue where the print copy you are using has non-standard double quote characters (quotes on the left lean to the left, while quotes on the right lean to the right). Once copied into Jupyter, you will need to change this to normal double quotes (they don't lean; instead, they are vertical).
After running this, we will see the following display:
