mohamed morsy
23 / 6 / 2018
library(plotly)
plot_ly(mtcars, x = mtcars$wt, y = mtcars$mpg, mode = "markers" )
plot_ly(mtcars, x = mtcars$wt, y = mtcars$mpg,
mode = "markers",
color = mtcars$cyl)
plot_ly(mtcars, x = mtcars$wt, y = mtcars$mpg,
mode = "markers",
color = as.factor(mtcars$cyl))
plot_ly(mtcars, x = mtcars$wt, y = mtcars$mpg,
mode = "markers",
color = mtcars$disp,
size = mtcars$hp)
# webgl > opengl
set.seed(2018-07-21)
temp <- rnorm(100, mean = 30, sd = 5)
pressure <- rnorm(100)
dtime <- 1:100
plot_ly(x = temp, y = pressure, z = dtime,
type = "scatter3d", mode = "markers",
color = temp)
data("airmiles")
plot_ly(x = time(airmiles), y= airmiles, mode = "line")
library(tidyr);
library(dplyr);
data("EuStockMarkets");
stocks <- as.data.frame(EuStockMarkets) %>%
gather(index, price) %>% # from short format to long format data needed for plotly
mutate(time = rep(time(EuStockMarkets), 4));
plot_ly(stocks, x= stocks$time, y = stocks$price,
color = stocks$index)
plot_ly(x = precip, type ="histogram")
plot_ly(iris, y = iris$Petal.Length,
color = iris$Species,
type = "box")
terrain <- matrix(rnorm(100*100), nrow = 100, ncol = 100)
plot_ly(z = terrain, type = "heatmap") # must be z
terrain2 <- matrix(sort(rnorm(100*100)),
nrow = 100, ncol = 100)
map <- plot_ly(z = terrain2, type = "surface")
state_pop <- data.frame(State = state.abb,
Pop = as.vector(state.x77[,1]))
state_pop$hover <- with(state_pop,
paste(state_pop$State, '<br>',
"Population",
state_pop$Pop))
borders <- list (color = toRGB("red"))
map_options <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showlakes = TRUE,
lakecolor = toRGB('white')
)
plot_ly(state_pop,
z = state_pop$Pop,
text = state_pop$hover,
type = 'choropleth',
locationmode = 'USA-states',
color = state_pop$Pop,
colors = 'Blues',
marker = list(line = borders)) %>%
layout(title = 'US Populationn in 1975',
geo = map_options)
library(ggplot2)
set.seed(100)
data("diamonds")
d <- diamonds[sample(nrow(diamonds), 1000),]
p <- ggplot(data = d,
aes (x = d$carat ,
y = d$price)) +
geom_point(aes(text = paste("Clarity:", d$clarity)),
size = 4) +
geom_smooth(aes( colour = d$cut, fill = d$cut )) +
facet_wrap(~ d$cut)
(gg <- ggplotly(p))