Reviewers: Megan A. Jones
After completing the previous tutorial,
you have an R object
p that contains a
ggplot plot. We’ll now make an interactive plot.ly plot.
If you have not completed the previous tutorial, the code for
p can be found
in the downloadable R code for this lesson, or complete the previous tutorial.
Now we can create an interactive plot.ly plot from the
p R object.
Create Plot.ly Interactive Plot
Plot.ly is a free to use, online interactive data viz site. If you have the plot.ly library installed, you can quickly export a ggplot graphic into plot.ly! (NOTE: it also works for python matplotlib)!! To use plotly, you need to setup an account. Once you’ve setup an account, you can get your key from the plot.ly site to make the code below work.
# install.packages("plotly") library(plotly) # your ggplot - object p
Create a local version of a plotly plot!
# plot your plot using plot_ly locally ggplotly(p)
Push a plot plot to your plotly account! Feel free to use NEON’s credentials for this week!
# setup your plot.ly credentials Sys.setenv("plotly_username"="yourUserName") Sys.setenv("plotly_api_key"="yourAPIkey") # generate the plot plotly_POST(p, filename='NEON SJER CHM vs Insitu Tree Height') # let anyone in the world see the plot!
Check out the results!
NEON Remote Sensing Data compared to NEON Terrestrial Measurements for the SJER field site.