knitr::opts_chunk$set(echo = TRUE)
Create a shiny interactive document with a plot of the spruce data.
library(ggplot2) spruce.df=read.csv("SPRUCE.csv") inputPanel(selectInput("plotg","Choose plot type", list("Regression Line","Points","Points with Segments"))) renderPlot({ g=ggplot(spruce.df, aes(x=BHDiameter,y=Height)) regression=g+geom_smooth(method="lm") pointplot=g+geom_point() segments=g+geom_point()+geom_line() if(input$plotg=="Regression Line") print(regression) if(input$plotg=="Points") print(pointplot) if(input$plotg=="Points with Segments") print(segments) })
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.