Below are the solutions to these exercises on visualizations with plotly.
#################### # # # Exercise 1 # # # #################### library(plotly) plot_ly ( x =c(1,2,3,4,5 ), y =c(6,7,8,9,10), type = "scatter" , mode = "lines" ) #################### # # # Exercise 2 # # # #################### library(plotly) plot_ly ( x =c(1,2,3,4,5 ), y =c(6,7,8,9,10), type = "scatter" , mode = "markers" ) #################### # # # Exercise 3 # # # #################### library(plotly) plot_ly ( x =c(1,2,3,4,5), y =c(6,7,8,9,10), type = "bar" , mode = "markers" ) #################### # # # Exercise 4 # # # #################### library(plotly) plot_ly (x =c(1, 2, 3,4,5 ), y =c(6, 7, 8,9,10 ), type = "scatter" , mode = "markers" , size =c( 1,5, 10,7,8 ), marker = list(color =c( "red", "blue" ,"green","black","yellow" ))) #################### # # # Exercise 5 # # # #################### library(plotly) plot_ly( z=volcano, type = "heatmap") #################### # # # Exercise 6 # # # #################### library(plotly) plot_ly ( x =c(1,2,3,4,5 ), y =c(6,7,8,9,10), type = "scatter" , mode = "lines", fill = "tozeroy" ) #################### # # # Exercise 7 # # # #################### library(plotly) plot_ly ( x =c(1,2,3,4,5 ), y =c(6,7,8,9,10), y3 =c(-6,-7,-8,-9,-10), type = "scatter", mode = "markers" ) %>% add_trace(x=x,y=y3 ) #################### # # # Exercise 8 # # # #################### library(plotly) plot_ly ( x =c(1,2,3,4,5 ), y =c(6,7,8,9,10), y3 =c(-6,-7,-8,-9,-10), type = "scatter", mode = "markers" ) %>% add_trace(x=x,y=y3 )%>% layout(legend = list( x = 1 , y =1 , bgcolor = "red" )) #################### # # # Exercise 9 # # # #################### library(plotly) axis_template <- list( showgrid = F , zeroline =F , nticks = 40 , showline =T , title = "AXIS" , mirror = "all" ) plot_ly ( x =c(1,2,3,4,5 ), y =c(6,7,8,9,10), type = "scatter", mode = "markers" ) %>% layout(xaxis = axis_template, yaxis = axis_template ) #################### # # # Exercise 10 # # # #################### library(plotly) axis_template <- list( showgrid = T , zeroline =T , nticks = 20 , showline =F , title = "AXIS" , mirror = "all" ) plot_ly ( x =c(1,2,3,4,5 ), y =c(6,7,8,9,10), type = "scatter", mode = "markers" ) %>% layout(xaxis = axis_template, yaxis = axis_template )
Leave a Reply