Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add legend to scatterplot3d in R

Tags:

r

scatter-plot

I would like to add legend to my scatterplot3d. I created 3 separate plot and overlay them into 1 plot so i don't know where the syntax for legend("topleft",inset=0.5) should go

Plot <-scatterplot3d(data$Size,data$Pct,data$bias1, type='h', zlim=c(-20,100), xlab="size", ylab= "Percent", zlab="Bias")

Plot$points3d (data$Size,data$Pct,data$Bias2,
  col="blue", type="h", pch=15, cex=.6)  

Plot$points3d(data$Size,data$Pct,data$Bias3,
  col="red", type="h", pch=4, cex=.6)  
like image 383
Amateur Avatar asked Feb 28 '12 06:02

Amateur


People also ask

What package is scatter3d in R?

The function scatter3d() uses the rgl package to draw and animate 3D scatter plots.

How do you make a 3D plot in R?

Creating 3D Plots in R Programming – persp() Function The persp() function which is used to create 3D surfaces in perspective view. This function will draw perspective plots of a surface over the x–y plane. persp() is defines as a generic function.


1 Answers

It's an old question. But I had the same issue and solved it with the following code. I have four timeseries with a duration of a year in a 3D plot.

As usual, I created the graphic like this:

s3d <- scatterplot3d(...)

And then just added the legend like this:

legend(s3d$xyz.convert(18, 0, 12), col= c("green","blue", "red", "black"), bg="white", lty=c(1,1), lwd=2, yjust=0, legend = c("2010", "2011", "2012", "Prognose für 2013"), cex = 1.1)
like image 71
user3793871 Avatar answered Sep 22 '22 17:09

user3793871