Dot Plots in R
How to make a dot plot in R. Dot plots show changes between two points in time or between two conditions.
Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Sign up for early access now.
Dot and Dumbbell Plots
library(plotly)
s <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/school_earnings.csv")
s <- s[order(s$Men), ]
fig <- plot_ly(s, x = ~Women, y = ~School, name = "Women", type = 'scatter',
mode = "markers", marker = list(color = "pink"))
fig <- fig %>% add_trace(x = ~Men, y = ~School, name = "Men",type = 'scatter',
mode = "markers", marker = list(color = "blue"))
fig <- fig %>% layout(
title = "Gender earnings disparity",
xaxis = list(title = "Annual Salary (in thousands)"),
margin = list(l = 100)
)
fig
Click to copy
Reference
See https://plotly.com/r/reference/#scatter for more information and chart attribute options!
What About Dash?
Dash for R is an open-source framework for building analytical applications, with no Javascript required, and it is tightly integrated with the Plotly graphing library.
Learn about how to install Dash for R at https://dashr.plot.ly/installation.
Everywhere in this page that you see fig
, you can display the same figure in a Dash for R application by passing it to the figure
argument of the Graph
component from the built-in dashCoreComponents
package like this:
library(plotly)
fig <- plot_ly()
# fig <- fig %>% add_trace( ... )
# fig <- fig %>% layout( ... )
library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)
app <- Dash$new()
app$layout(
htmlDiv(
list(
dccGraph(figure=fig)
)
)
)
app$run_server(debug=TRUE, dev_tools_hot_reload=FALSE)
Click to copy