- Plotly is a free and open-source graphing library for R.
Plotly is a free and open-source graphing library for R.
Plotly’s R graphing library makes interactive, publication-quality graphs.
Plotly is a free and open-source graphing library for R.
Plotly’s R graphing library makes interactive, publication-quality graphs.
You can view the source, report issues or contribute on GitHub.
Plotly is a free and open-source graphing library for R.
Plotly’s R graphing library makes interactive, publication-quality graphs.
You can view the source, report issues or contribute on GitHub.
plotly is an R package for creating interactive web-based graphs via the open source JavaScript graphing library plotly.js.
Plotly is a free and open-source graphing library for R.
Plotly’s R graphing library makes interactive, publication-quality graphs.
You can view the source, report issues or contribute on GitHub.
plotly is an R package for creating interactive web-based graphs via the open source JavaScript graphing library plotly.js.
As of version 2.0 (November 17, 2015), graphs created with the plotly R package are rendered locally through the htmlwidgets framework.
install.package() function to install the plotly R package from CRAN!install.packages("plotly")
install.package() function to install the plotly R package from CRAN!install.packages("plotly")
plotly from GitHub via the devtools R package:devtools::install_github("ropensci/plotly")
install.package() function to install the plotly R package from CRAN!install.packages("plotly")
plotly from GitHub via the devtools R package:devtools::install_github("ropensci/plotly")
RStudio users should ensure that they are using the latest RStudio release in order to ensure compatibility with the htmlwidgets R package.By default, the plotly R package runs locally in your web browser or in the RStudio viewer.
library(plotly) plot_ly(midwest, x = ~percollege, color = ~state, type = "box", height=350, width=800)
Simply printing the plot object will render the chart locally in your web browser or in the RStudio viewer.
Graphs created with the plotly R package are interactive!
Click on legend entries to hide/show traces, click-and-drag on the chart to zoom, double-click to autoscale, shift-and-drag to pan.
See https://plotly.com/r/basic-charts/ for more!
plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length)
plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species)
plot_ly(diamonds[sample(nrow(diamonds), 1000), ], x = ~carat, y = ~price, color = ~carat, size = ~carat)
plot_ly(
diamonds[sample(nrow(diamonds), 1000), ], x = ~carat, y = ~price,
# Hover text:
text = ~paste("Price: ", price, '$<br>Cut:', cut),
color = ~carat, size = ~carat
)
mtcars$am[which(mtcars$am == 0)] <- 'Automatic'
mtcars$am[which(mtcars$am == 1)] <- 'Manual'
mtcars$am <- as.factor(mtcars$am)
fig <- plot_ly(mtcars, x = ~wt, y = ~hp, z = ~qsec, color = ~am, colors = c('#BF382A', '#0C4B8E'))
fig <- fig %>% add_markers()
fig <- fig %>% layout(scene = list(xaxis = list(title = 'Weight'),
yaxis = list(title = 'Gross horsepower'),
zaxis = list(title = '1/4 mile time')))
fig
See https://plot.ly/r/reference/#scatter3d for more information and chart attribute options!
Add mode and type arguements to make line graphs. They’re of course useful for showing change over time:
data("airmiles")
plot_ly(x = time(airmiles), y = airmiles, mode='lines',type='scatter', height=350)
You can show multiple lines by specifying the column in the data frame that separates the lines:
library(tidyr)
library(dplyr)
data("EuStockMarkets")
stocks <- as_tibble(EuStockMarkets) %>%
gather(index, price) %>%
mutate(time = rep(time(EuStockMarkets), 4))
plot_ly(x = stocks$time, y = stocks$price, color = stocks$index, type = 'scatter', mode = 'lines')
dens <- with(diamonds, tapply(price, INDEX = cut, density)) df <- data.frame( x = unlist(lapply(dens, "[[", "x")), y = unlist(lapply(dens, "[[", "y")), cut = rep(names(dens), each = length(dens[[1]]$x)) ) fig <- plot_ly(df, x = ~x, y = ~y, color = ~cut) fig <- fig %>% add_lines() fig
See https://plot.ly/r/reference/#scatter for more information and chart attribute options!
Histograms are great for showing how counts of data are distributed. Use the type = "histogram" argument.
plot_ly(x = ~rnorm(50), type = "histogram",height=350, width = 600)
Use alpha to set the opacity to make overlayed histograms easier to see:
fig <- plot_ly(alpha = 0.6) fig <- fig %>% add_histogram(x = ~rnorm(500)) fig <- fig %>% add_histogram(x = ~rnorm(500) + 1) fig <- fig %>% layout(barmode = "overlay") fig
See https://plot.ly/r/reference/#histogram for more information and chart attribute options!
plot_ly(ggplot2::diamonds, y = ~price, color = ~cut, type = "box")
See https://plot.ly/r/reference/#box for more information and chart attribute options!
plot_ly(z = ~volcano) %>% add_surface()
df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv")
df$hover <- with(df, paste(state, '<br>', "Beef", beef, "Dairy", dairy, "<br>",
"Fruits", total.fruits, "Veggies", total.veggies,
"<br>", "Wheat", wheat, "Corn", corn))
# give state boundaries a white border
l <- list(color = toRGB("white"), width = 2)
# specify some map projection/options
g <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showlakes = TRUE,
lakecolor = toRGB('white')
)
fig <- plot_geo(df, locationmode = 'USA-states')
fig <- fig %>% add_trace(
z = ~total.exports, text = ~hover, locations = ~code,
color = ~total.exports, colors = 'Purples'
)
fig <- fig %>% colorbar(title = "Millions USD")
fig <- fig %>% layout(
title = '2011 US Agriculture Exports by State<br>(Hover for breakdown)',
geo = g
)
fig
With ggplotly() by Plotly, you can convert your ggplot2 figures into interactive ones powered by plotly.js, ready for embedding into Dash applications.
library(plotly)
dat <- data.frame(
time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")),
total_bill = c(14.89, 17.23)
)
p <- ggplot(data=dat, aes(x=time, y=total_bill)) +
geom_bar(stat="identity")
fig <- ggplotly(p)
fig
You can publish your charts to the web with Plotly’s web service.
Sys.setenv("plotly_username"="your_plotly_username")
Sys.setenv("plotly_api_key"="your_api_key")
library(plotly) p <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box") api_create(p, filename = "r-docs-midwest-boxplots")