我正在使用 plotly 将数据集可视化为交互式绘图,该绘图可用于仪表板中的 Shiny 应用程序。我正在使用 plotly 包,因为它似乎非常适合我做这样的事情。我想用线条和标记创建一个图。当尝试使用下面的代码进行跟踪时,我只得到标记,中间没有线
plot_ly(cube_eduexpgdp, x = ~year) %>%
add_trace(y = ~expenditure_gdp, mode = "lines+markers",
color = ~country_name, line = list(shape = "linear")) %>%
layout(title = "Government expenditures as percentage of GDP",
yaxis = list(title = "Expenditures (%)"),
xaxis = list(title = "Year"))
此 tutorial from plotly建议使用以下代码来完成。当我使用此代码时,我会得到一个空 Canvas ,当我将鼠标悬停在工具提示上时,它会在工具提示上显示分组数据点的值。
plot_ly(cube_eduexpgdp, x = ~year, y = ~expenditure_gdp,
color = ~country_name) %>%
add_lines() `
有没有人可以帮助我?将不胜感激!
最佳答案
我遇到了同样的错误,发现它是由于尝试绘制分组数据框引起的,因此必须 ungroup()
第一的。在这里找到:R - plotly invisible lines
关于r - Plotly 不显示线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50889627/