plotly plot 中只显示标记而不是线条和标记
Only markers are displayed instead of lines and markers in plotly plot
我在下面绘制了情节图,其中虽然我选择 lines+markers
作为 mode
,但我只得到 lines
。为什么会这样?
sumscope2<-structure(list(Year = c(1962, 1976, 1988, 1989, 1991, 1997, 2002,
2008), Country = c("Algeria", "Algeria", "Algeria", "Algeria",
"Algeria", "Algeria", "Algeria", "Algeria"), Scope = c(2, 9,
3, 2, 15, 3, 23, 4)), class = c("grouped_df", "tbl_df", "tbl",
"data.frame"), row.names = c(NA, -8L), groups = structure(list(
Year = c(1962, 1976, 1988, 1989, 1991, 1997, 2002, 2008),
.rows = structure(list(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -8L), .drop = TRUE))
library(plotly)
fig <- plot_ly(data = sumscope2, x = ~Year, y = ~Scope,mode = 'lines+markers',
marker = list(size = 10,
color = 'rgba(255, 182, 193, .9)',
line = list(color = 'rgba(152, 0, 0, .8)',
width = 2)),
text=paste("Year :", sumscope2$Year,
"<br> Count of Scopes :", sumscope2$Scope),
hoverinfo="text"
)%>%
layout(title="Count of Scope per country and year",
xaxis=list(tickvals=~Year,ticktext=~Year,dtick = 5),
yaxis=list(tickvals=~Scope,ticktext=~Scope,dtick = 5)
)
fig
plot_ly()
期望将 data.frame
传递给它的 data
参数。
您的数据是:
> is(sumscope2)
[1] "grouped_df" "tbl_df" "tbl" "data.frame" "list" "oldClass" "vector"
请检查以下内容:
sumscope2 <- structure(list(Year = c(1962, 1976, 1988, 1989, 1991, 1997, 2002,
2008), Country = c("Algeria", "Algeria", "Algeria", "Algeria",
"Algeria", "Algeria", "Algeria", "Algeria"), Scope = c(2, 9,
3, 2, 15, 3, 23, 4)), class = c("grouped_df", "tbl_df", "tbl",
"data.frame"), row.names = c(NA, -8L), groups = structure(list(
Year = c(1962, 1976, 1988, 1989, 1991, 1997, 2002, 2008),
.rows = structure(list(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -8L), .drop = TRUE))
library(plotly)
fig <- plot_ly(
data = as.data.frame(sumscope2),
x = ~ Year,
y = ~ Scope,
type = "scatter",
mode = "lines+markers",
marker = list(
size = 10,
color = 'rgba(255, 182, 193, .9)',
line = list(color = 'rgba(152, 0, 0, .8)',
width = 2)
),
line = list(color = 'rgba(152, 0, 0, .8)',
width = 2),
text = paste(
"Year :",
sumscope2$Year,
"<br> Count of Scopes :",
sumscope2$Scope
),
hoverinfo = "text"
) %>% layout(
title = "Count of Scope per country and year",
xaxis = list(
tickvals = ~ Year,
ticktext = ~ Year,
dtick = 5
),
yaxis = list(
tickvals = ~ Scope,
ticktext = ~ Scope,
dtick = 5
)
)
fig
我在下面绘制了情节图,其中虽然我选择 lines+markers
作为 mode
,但我只得到 lines
。为什么会这样?
sumscope2<-structure(list(Year = c(1962, 1976, 1988, 1989, 1991, 1997, 2002,
2008), Country = c("Algeria", "Algeria", "Algeria", "Algeria",
"Algeria", "Algeria", "Algeria", "Algeria"), Scope = c(2, 9,
3, 2, 15, 3, 23, 4)), class = c("grouped_df", "tbl_df", "tbl",
"data.frame"), row.names = c(NA, -8L), groups = structure(list(
Year = c(1962, 1976, 1988, 1989, 1991, 1997, 2002, 2008),
.rows = structure(list(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -8L), .drop = TRUE))
library(plotly)
fig <- plot_ly(data = sumscope2, x = ~Year, y = ~Scope,mode = 'lines+markers',
marker = list(size = 10,
color = 'rgba(255, 182, 193, .9)',
line = list(color = 'rgba(152, 0, 0, .8)',
width = 2)),
text=paste("Year :", sumscope2$Year,
"<br> Count of Scopes :", sumscope2$Scope),
hoverinfo="text"
)%>%
layout(title="Count of Scope per country and year",
xaxis=list(tickvals=~Year,ticktext=~Year,dtick = 5),
yaxis=list(tickvals=~Scope,ticktext=~Scope,dtick = 5)
)
fig
plot_ly()
期望将 data.frame
传递给它的 data
参数。
您的数据是:
> is(sumscope2)
[1] "grouped_df" "tbl_df" "tbl" "data.frame" "list" "oldClass" "vector"
请检查以下内容:
sumscope2 <- structure(list(Year = c(1962, 1976, 1988, 1989, 1991, 1997, 2002,
2008), Country = c("Algeria", "Algeria", "Algeria", "Algeria",
"Algeria", "Algeria", "Algeria", "Algeria"), Scope = c(2, 9,
3, 2, 15, 3, 23, 4)), class = c("grouped_df", "tbl_df", "tbl",
"data.frame"), row.names = c(NA, -8L), groups = structure(list(
Year = c(1962, 1976, 1988, 1989, 1991, 1997, 2002, 2008),
.rows = structure(list(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -8L), .drop = TRUE))
library(plotly)
fig <- plot_ly(
data = as.data.frame(sumscope2),
x = ~ Year,
y = ~ Scope,
type = "scatter",
mode = "lines+markers",
marker = list(
size = 10,
color = 'rgba(255, 182, 193, .9)',
line = list(color = 'rgba(152, 0, 0, .8)',
width = 2)
),
line = list(color = 'rgba(152, 0, 0, .8)',
width = 2),
text = paste(
"Year :",
sumscope2$Year,
"<br> Count of Scopes :",
sumscope2$Scope
),
hoverinfo = "text"
) %>% layout(
title = "Count of Scope per country and year",
xaxis = list(
tickvals = ~ Year,
ticktext = ~ Year,
dtick = 5
),
yaxis = list(
tickvals = ~ Scope,
ticktext = ~ Scope,
dtick = 5
)
)
fig