studyGroup icon indicating copy to clipboard operation
studyGroup copied to clipboard

Interactive plots in R!

Open ttimbers opened this issue 6 years ago • 4 comments

Come learn about how to use plotly in R to make interactive visualizations!

When: Thursday, Aug 30, 9:00 am

Where: Koerner Library, room 216; map

More details to come from Vishal @link2vishal!

ttimbers avatar Aug 02 '18 04:08 ttimbers

Awesome, thanks Tiffany!

On Wed, Aug 1, 2018, 9:57 PM Tiffany A. Timbers [email protected] wrote:

Come learn about how to use plotly in R to make interactive visualizations!

When: Thursday, Aug 30, 9:00 am

Where: Koerner Library, room 216; map

More details to come from Vishal!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/minisciencegirl/studyGroup/issues/193, or mute the thread https://github.com/notifications/unsubscribe-auth/AHaRL5WDVjzOFAWNqOClet2QMJjEtKqDks5uMobXgaJpZM4VrocF .

mairindeith avatar Aug 02 '18 16:08 mairindeith

@link2vishal: Could you please let us know if we need to install anything? Thanks!

minisciencegirl avatar Aug 23 '18 16:08 minisciencegirl

For this session of Interactive plots in R, we will be working with plotly package. We will also work to transform ggplot into interactive plots using plotly. You can install the packages using:

install.packages("plotly") install.packages("ggplot2")

See you on this Thursday at the R Study Group session

link2vishal avatar Aug 27 '18 19:08 link2vishal

#Group work activity for interactive plots using "plotly" package

library(plotly) library(ggplot2)

#mpg dataset from the package ggplot2 data(mpg, package = "ggplot2")

str(mpg) mpg$cyl <- as.factor(mpg$cyl)

#basic plotly interactive graph plot_ly(mpg, x = ~cty, y = ~hwy)

#grouping data by number of cylinders plot_ly(mpg, x = ~cty, y = ~hwy, color = ~cyl)

#OR we can use pipe along with add_markers function plot_ly(mpg, x = ~cty, y = ~hwy) %>% add_markers(name = ~cyl, color = ~cyl)

#change the type of charts using type = "" plot_ly(mpg, x = ~cty, y = ~hwy, color = ~cyl, type = "box")

#3D plots using plotly plot_ly(mpg, x = ~cty, y = ~hwy, z = ~cyl, color =~cyl)

#change the type of chart using type = ""
plot_ly(mpg, x = ~cty, y = ~hwy, z = ~cyl, color =~cyl, type = "lines")

#using ggplotly to add interactie function in ggplot graphs p <- ggplot(mpg, aes(class, hwy, color = class, fill = class)) + geom_boxplot(alpha = 0.2) + stat_summary( aes(label = round(..y..,2)), fun.y = "median", geom = "text", colour= "black", show.legend = F, vjust = -2) + stat_summary(fun.y = "median", geom = "point", color = "black", show.legend = F) ggplotly(p)

q <- ggplot(mpg, aes(class, hwy, color = class, fill = class)) + geom_boxplot(alpha = 0.2) ggplotly(q)

#Transforming Corrplot to Interactive plot pm <- GGally::ggpairs(iris) ggplotly(pm)

link2vishal avatar Aug 31 '18 19:08 link2vishal