logo
down
shadow

Plot_ly color not corresponding to z


Plot_ly color not corresponding to z

By : Prachi Bari
Date : November 19 2020, 03:01 PM
hope this fix your issue I am trying to plot a 3d graph by using plot_ly , Use surfacecolor instead of color:
code :
plot_ly(x = ~ x, y = ~ y, z= ~ z, surfacecolor = ~ z_col) %>% add_surface()


Share : facebook icon twitter icon
plot_ly function in R

plot_ly function in R


By : Akshil Savalia
Date : March 29 2020, 07:55 AM
I wish this help you I look at Plotly guideline but I could not find a way to rename x and y labels. Any advice? , In R, you store that info in lists. Like this
code :
p1<-plot_ly(growthData_b, x = ~x, y = ~y) %>% 
  add_lines(data = growthData_b, x = ~x, y = ~X0.025,name = "0.025 percentile",color = I("black")) %>% 
  add_lines(data = growthData_b, x = ~x, y = ~X0.975,name = "0.975 percentile",color = I("black")) %>%
  add_markers(x = ~x, y = ~y,color =I("blue")) %>% 

  layout(xaxis = list(title = "X Axis"), yaxis = list(title = "Y Axis"))
Adding a categorical color to plot_ly markers invert the size of the points displayed

Adding a categorical color to plot_ly markers invert the size of the points displayed


By : vf04
Date : March 29 2020, 07:55 AM
This might help you I'm trying to make a plot with plotly that have colors representing some class (factor ff in my example) and the size representing the population size (column ss in my example). Plotting with a constant color makes the graph ok, i.e. the size of the dots are representative. However, if I add the color=~ff argument to the call, the sizes displayed change and seems inverted! , I am not sure how you set your sizeref, but have you tried this:
code :
plot_ly(data = dd, x = ~xx, y = ~yy, color = ~ff, size= ~ss) %>% 
add_markers(marker = list(sizeref = 3, sizemode= "diameter"))
What exactly is the z argument in plot_ly?

What exactly is the z argument in plot_ly?


By : user2354042
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The problem with your above code is, that you haven't specified the trace type - and what you need to pass to the z argument depends on this specification.
Passing the arguments x, y ,z suggests you want to display a scatter3d plot - you can test this by dropping add_surface():
code :
z <- runif(50,0,1) 
y <- runif(50,1,2)
x <- runif(50,3,6)
plot_ly(x = x, y = y, z = z)
# install.packages("listviewer")

library(plotly)
library(listviewer)
schema(jsonedit = interactive())
z <- runif(50,0,1) 
y <- runif(50,1,2)
x <- runif(50,3,6)
plot_ly(x = x, y = y, z = z, type = 'mesh3d')
How do you add a customized color index for mesh3d plots in Plot_ly?

How do you add a customized color index for mesh3d plots in Plot_ly?


By : user2357186
Date : March 29 2020, 07:55 AM
wish of those help I can easily make a mesh3d plot in R: , Welcome to SO!
You can add a custom colorRamp like this:
code :
library(plotly)
x <- runif(50, 0, 110)
y <- runif(50, 0, 1)
z <- runif(50, 1, 2)

plot_ly(x = ~x, y = ~y, z = ~z, intensity = ~z, type = 'mesh3d', colors = colorRamp(c("blue", "lightblue", "chartreuse3", "yellow", "red")))
plot_ly with transforms and color mapping

plot_ly with transforms and color mapping


By : user2554131
Date : March 29 2020, 07:55 AM
like below fixes the issue It doesn't seem to like the factor in the color in combination with the filter. It looks like stuff is getting shuffled and screwed up, e.g. color = ~factor(carb, levels = unique(carb)) will give you yet another selection and plot.
Below is working with a factor (including the color in the marker). Specifying just color = ~carb would work as well. I understand none of these really give you the same plot / legend though.
code :
library(plotly)
library(magrittr)

plot_ly(
  data = mtcars %>% tibble::rownames_to_column("id"),
  x = ~mpg, y = ~disp, text = ~id,
  type = "scatter", mode = "markers+text",
  marker = list(color = ~as.factor(carb), size = 10, opacity = 0.8),
  transforms = list(
    list(
      type = "filter",
      target = ~cyl,
      operation = "=",
      value = sort(unique(mtcars$cyl))[1])))
library(plotly)
library(magrittr)

xx <- mtcars[order(mtcars$carb), ]

plot_ly(
  data = xx %>% tibble::rownames_to_column("id"),
  x = ~mpg, y = ~disp, text = ~id, color = ~factor(carb),
  type = "scatter", mode = "markers+text",
  marker = list(size = 10, opacity = 0.8),
  transforms = list(
    list(
      type = "filter",
      target = ~xx$cyl,
      operation = "=",
      value = sort(unique(xx$cyl))[1])))
library(godmode)
arrange_safe_new <- function(x, y) x
godmode:::assignAnywhere("arrange_safe", arrange_safe_new)
Related Posts Related Posts :
  • how to loop for division funciton in r
  • Why does ggplot not allow suppressing of messages generated by its geoms?
  • Download multiple excel files linked through urls in R
  • sparklyr : spark_apply function is not working in cluster mode
  • dplyr mutate - How do I pass one row as a function argument?
  • R selecting rows by conditions given in an external table
  • Native regex way to replace multiple leading chars with equal number spaces
  • stan - difficulty vectorizing
  • How to define a function that calls shiny functions?
  • How to count number of observations in a "n" dimensional range in R
  • Superimposing asymmetric t-distribution using ggplot2
  • Makefile to render all targets of all .Rmd files in directory
  • Authentication failure with rdrop2
  • DT data table display error
  • Issue when adding new rows (with nested dataframes within) to a dataframe
  • R-How to compare two dataframe and update list column value
  • Series vector for approximating pi
  • what is difference between "variance explained " in Random Forest and "merror" in XGBoost
  • R - Cast dataframe on unique rows - reshape2
  • ggplot2: plot correct proportions using geom_bar
  • Speedup query for R data.table - can this two-argument function be applied by group more quickly?
  • apply a function to several columns at once with mutate
  • R 'cowplot' neatly produce gridded plot with shared (common) legends and unique legends
  • Repeat R script for many times and save results to text file
  • How to negative lookbehind for special characters
  • data.table inner join produces error when no match is found
  • Create a new column base on existing column, but row above
  • Is there a way to visualize the process of source() in RStudio?
  • google places api consumes 10 request but I am doing only 1
  • Statistical mode of a categorical variable in R (using mlv)
  • Using for-loop to mutate a data.frame in r
  • Make plot with regression line for mixed model
  • Shortcut to select matces cases in R studio
  • vectoriced norm/matrix multiplication
  • Negative log10 transformation in R
  • Plot data with duplicate points
  • Visualizing crosstab tables with a plot in R - changing colours
  • How to manually modify automated numbers and labels in plot
  • How can I follow any redirections of a url in R?
  • Add jitter to box plot using markers in plotly
  • Adding an extra item to the legend
  • ggplot fills in data in the wrong order
  • Convert list to data frame
  • R: filtering by list(s) of strings and returning all results that start with the content of the lists
  • R:How to attach parts of a data frame with different headers and/or an overflowing piece of the dat frame
  • How to use 'par' for manipulating plot margins?
  • Can dplyr::case_when return mix of NAs and non-NAs?
  • Text preprocessing and topic modelling using text2vec package
  • Uploading multiple files in Shiny, process the files, rbind the results and return a download
  • R levelplot: color green-white-red (white on 0) according to one variable, but show the values of another variable
  • Why [i] doesn't point to the starting point in a vector
  • In R after generating a mvrnorm distribution, Y, what does Y[,1] do?
  • expand a data frame to have as many rows as range of two columns in original row
  • Getting started with R and CFA
  • Re order x-axis in ggplot so time goes from 12AM to 11PM in R
  • R - Automatically stack every nth column of a data frame and save them as new objects
  • How to format dplyr output in R into doubles (or other workable format)?
  • Dataframe to matrix conversion using tapply turns zeros to NAs
  • Smallest multiple of 1:20 - How can I make it quicker?
  • How to specify the size of a graph in ggplot2 independent of axis labels
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org