Black Lives Matter. Please consider donating to Black Girls Code today.

Can't display both discrete & non-discrete data on same axis when use subplot()

I am having some trouble here using subplot(). My main goal is to create a bar+ line chart and a pie chart side by side on a slide.

When I run the codes for my bar+ line chart, the all the elements display perfectly. (no warning message)

When I run the subplot() command to put 2 charts together, the line disappeared, with an additional warning message – Can’t display both discrete & non-discrete data on same axis

How do I solve this problem so that I can keep the line when using subplot()?

p1 <- plot_ly(data1, x = ~ Year ,width = 480) %>%
add_bars(y = ~ Canada, name = “Canada”, showlegend = T
)%>%
add_bars(y = ~ US, name = “US” ,showlegend =T
) %>%
add_trace(y = ~ IPPI, name = “IPPI”, showlegend = T, mode= “lines”, type = “scatter”,
line= list(width = 2.5 , color = “black”), yaxis = “y2”) %>%
layout(yaxis2 = ay, yaxis = list(title = “”, showgrid = FALSE, zeroline = FALSE)
)

p2 <- data2 %>%
group_by(Countries) %>%
plot_ly(labels = ~ Countries, values = ~ Amount, type = “pie”, width = 480,
showlegend = FALSE, visible = TRUE,
textposition = “inside”,
textinfo = “label+percent”,
insidetextfont = list(color = ‘#FFFFFF’),
hoverinfo = “text”,
text = ~paste(Countries, Amount),
domain = list(x = c(0.6, 1.2), y = c(0.0, 1)),
marker = list(colors = colors,
line = list(color = ‘#FFFFFF’, width = 1)))%>%
layout(title = “”,
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE, showline = FALSE, title = “”),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE, showline = FALSE, title = “”)
)

subplot(p1,p2) %>% layout(width = 1000)