Ric*_*ard 5 r shiny plotly r-plotly
我正在使用 plotly 将数据集可视化为交互式绘图,该绘图可用于仪表板中的闪亮应用程序。我正在使用 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"))
Run Code Online (Sandbox Code Playgroud)
这个来自 plotly 的教程建议使用以下代码来完成。当我使用此代码时,我会得到一个空画布,当我将鼠标悬停在工具提示上时,它会在工具提示上显示分组数据点的值。
plot_ly(cube_eduexpgdp, x = ~year, y = ~expenditure_gdp,
color = ~country_name) %>%
add_lines() `
Run Code Online (Sandbox Code Playgroud)
有没有人可以帮助我?将不胜感激!
如果没有可重现的示例,我只能在这里猜测,但这可能是由于继承和/或plotly默认值造成的。下面的代码有帮助吗?
plot_ly(cube_eduexpgdp, x = ~year, type = 'scatter', mode = 'markers') %>%
add_trace(y = cube_eduexpgdp[['expenditure_gdp']], mode = "lines+markers",
color = cube_eduexpgdp[['country_name']], line = list(shape = "linear"), inherit = FALSE) %>%
layout(title = "Government expenditures as percentage of GDP",
yaxis = list(title = "Expenditures (%)"),
xaxis = list(title = "Year"))
Run Code Online (Sandbox Code Playgroud)