r - Melting data to produce a plot using a 3D scatter plot for frequency -


using example code here:

library(plotly)  data <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderdatafiveyear.csv")  data_2007 <- data[which(data$year == 2007),] data_2007 <- data_2007[order(data_2007$continent, data_2007$country),] data_2007$size <- data_2007$pop colors <- c('#4ac6b7', '#1972a4', '#965f8a', '#ff7070', '#c61951')  p <- plot_ly(data_2007, x = ~gdppercap, y = ~lifeexp, z = ~pop, color = ~continent, size = ~size, colors = colors,              marker = list(symbol = 'circle', sizemode = 'diameter'), sizes = c(5, 150),              text = ~paste('country:', country, '<br>life expectancy:', lifeexp, '<br>gdp:', gdppercap,                            '<br>pop.:', pop)) %>%   layout(title = 'life expectancy v. per capita gdp, 2007',          scene = list(xaxis = list(title = 'gdp per capita (2000 dollars)',                       gridcolor = 'rgb(255, 255, 255)',                       range = c(2.003297660701705, 5.191505530708712),                       type = 'log',                       zerolinewidth = 1,                       ticklen = 5,                       gridwidth = 2),                yaxis = list(title = 'life expectancy (years)',                       gridcolor = 'rgb(255, 255, 255)',                       range = c(36.12621671352166, 91.72921793264332),                       zerolinewidth = 1,                       ticklen = 5,                       gridwith = 2),                zaxis = list(title = 'population',                             gridcolor = 'rgb(255, 255, 255)',                             type = 'log',                             zerolinewidth = 1,                             ticklen = 5,                             gridwith = 2)),          paper_bgcolor = 'rgb(243, 243, 243)',          plot_bgcolor = 'rgb(243, 243, 243)') 

using possible produce 3d scatter plot 3 different dimensions.

i have following dataset:

grid <- structure(list(stock = structure(1:6, .label = c("stock1", "stock2",  "stock3", "stock4", "stock5", "stock6"), class = "factor"), company = structure(1:6, .label = c("company1",  "company2", "company3", "company4", "company5", "company6"), class = "factor"),      predirctor = structure(1:6, .label = c("predictor1", "predictor2",      "predictor3", "predictor4", "predictor5", "predictor6"), class = "factor"),      count = c(6l, 12l, 4l, 9l, 15l, 23l)), .names = c("stock",  "company", "predirctor", "count"), class = "data.frame", row.names = c(na,  -6l)) 

i use previous 3d scatter plot in order vizualize data. 3 dimensions are: stock, company , predirctor. , count column number. using code:

p <- plot_ly(df, x = df$stock, y = df$company, z = df$predirctor,         marker = list(color = df$count, colorscale = c('#ffe1a1', '#683531'), showscale = true)) %>%   add_markers() %>%   layout(scene = list(xaxis = list(title = 'weight'),                      yaxis = list(title = 'gross horsepower'),                      zaxis = list(title = '1/4 mile time')),          annotations = list(            x = 1.13,            y = 1.05,            text = 'miles/(us) gallon',            xref = 'paper',            yref = 'paper',            showarrow = false          )) 

i take lines of plot. can understand why happening because data needed plot must different numbers 3 dimensions. having count column have 1 dimension. using plot when see can see example stock1-company1-predirctor1 has count 6. instead of numbers in every line have labels. there way melt data in order produce graph?


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -