Graphic and line chart

I want to build a bar with a line chart in R with a chart.

My first attempt was

p <- plot_ly(
  x = c(1,2,3,4,5),
  y = c(1,2,1.5,3,2),
  type='scatter',
  mode='lines',
  line = list(color = 'black')
)
add_trace(
  p,
  x = c(1,2,3,4,5),
  y = c(0.5,0.7,0.6,0.9,0.8),
  type='bar',
  marker = list(color = 'red')
)

The result is correct, but I get the following warning:

Warning message: The following attributes do not exist: 'mode', 'line'

I assume that the stroke graph in add_trace()cannot handle parameters from lineand to modethe function plot_ly(). So I changed the order:

p <- plot_ly(
  x = c(1,2,3,4,5),
  y = c(0.5,0.7,0.6,0.9,0.8),
  type='bar',
  marker = list(color = 'red')
)
add_trace(
  p,
  x = c(1,2,3,4,5),
  y = c(1,2,1.5,3,2),
  type='scatter',
  mode='lines',
  line = list(color = 'black')
)

This time I get the following message, and the red markers appear on the black line chart.

Marker object specified, but markers are not in Add markers to ... mode

How can i fix this? (I am using the R plotly 4.1.0 package)

+4
source share
1

plotly 4.0.1, mode='lines+markers' mode='lines', .

- , -

( ), , :

p <- plot_ly(x = c(1,2,3,4,5),
             y = c(0.5,0.7,0.6,0.9,0.8),
             type='bar',
             marker = list(color = 'red', opacity=0)
     )

add_trace(p,
          x = c(1,2,3,4,5),
          y = c(1,2,1.5,3,2),
          type='scatter',
          mode='lines+markers',
          line = list(color = 'black')
     )
+5

Source: https://habr.com/ru/post/1649917/


All Articles