Issue changing marker color in R plotly scatter plot

slabofguinness

The following code produces a plot with red markers:

trace_0 <- rnorm(100, mean = 5)
trace_1 <- rnorm(100, mean = 0)
x <- c(1:100)

data <- data.frame(x, trace_0, trace_1)

plot_ly(data, x = ~x, y = ~trace_0, type = 'scatter', mode = 'markers',
        marker = list(color='red'))

enter image description here

If I try to add a line I get unwanted red markers also:

plot_ly(data, x = ~x, y = ~trace_0, type = 'scatter', mode = 'markers',
        marker = list(color='red'))%>%
  add_trace(y = ~trace_1, mode = 'lines')

enter image description here

and a complaint from plot_ly:

A marker object has been specified, but markers is not in the mode
Adding markers to the mode...

Could somebody please explain where I'm going wrong here? Thanks.

MLavoie

This will give you what you want:

plot_ly(data, x = ~x) %>%
add_trace(y = ~trace_0, mode = 'markers', marker = list(color='red')) %>%
  add_trace(y = ~trace_1, mode = 'lines')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Plotly R order scatter plot legend entries

Color coding error bars in a plotly scatter plot

Scatter Plot on Plotly Map

Interactive Scatter plot in R using Plotly and Shiny

color issue in scatter plot with matplotlib

Changing 3D scatter plot color based on specific column

Changing the color of points in scatter plot for different dummy values

Changing margins of a 3d scatter plot using plotly- R

R plotly: Add text in polar scatter plot

How do I create weighted scatter plot / bubble chart with color gradient using plotly R

How to change color of text in plotly scatter and different marker?

Changing the color of legend in plot for R

Categorical Scatter Plot with Plotly

Trying to create a scatter plot where the marker and color is cycled such that colour is changed after the 1 cycle of marker is complete

Change legend marker size for Plotly scatter plot (bubble chart) in Python

Python plotly scatter chart, take marker color from dataframe

R color scatter plot points based on values

Plot issue while changing axes scales on matplotlib scatter plot

How to give color to a class in scatter plot in R?

Plotly: How to add extra information to marker of 3D scatter plot?

Changing Dimensions of downloaded plot of plotly in r shiny

Plotly - "grouped" scatter plot

how to change the grid line color in plotly scatter plot?

Issue adding second variable to scatter plot in R

Change Plotly scatter plot color

Plotly: Scatter plot with dropdown menu and color by group

R Scatter Plot Issue

R Plotly - Assign the color of a marker by its size

how to assign same color to marker and marker border in px.scatter() plot?