簡體   English   中英

Plotly(在 R 中)中關於“標記”的錯誤消息

[英]Error Message in Plotly (in R) about "markers"

代碼塊...

library(plotly)
library(tidyverse)

my_fav_graph_SO <- function(my_df, my_levels) 
{

  x_axis <- list(
    title = "Variable Name",
    range = my_levels)

  primary_y_axis <- list(
   title = "coeff")

    p <- plot_ly() %>%

    add_lines(x = ~ my_df$factor_level,
              y = ~ my_df$coeff,
              yaxis = primary_y_axis,
              marker = list(color = "blue")) %>%

    layout(
      title = "graph",
      xaxis = x_axis,
      yaxis = primary_y_axis)

  p
}

df <- data.frame(factor_level = c("Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"),
                 exposure = c(50, 70, NA, 40, 45, 78, 42, 22, 28, 49, 50, 31),
                 coeff = c(1.1, 1.2, NA, 1.3, 1.8, 1.6, 1.4, 1.3, 1.2, 1.1, 1.5, 1.3))

my_levels = c("Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces")

df$factor_level <- factor(df$factor_level, levels = my_levels)

my_fav_graph_SO(df, my_levels)

圖形繪制正常,但我收到警告:

已指定標記對象,但標記不在模式中

向模式添加標記...

任何人都可以建議如何擺脫這個警告嗎? 我不確定我做錯了什么。

謝謝。

您正在通過add_lines添加線跡,但通過marker = list(color = "blue")指定標記顏色。 marker更改為line讓您擺脫警告:

library(plotly)
library(tidyverse)

my_fav_graph_SO <- function(my_df, my_levels) 
{

  x_axis <- list(
    title = "Variable Name",
    range = my_levels)

  primary_y_axis <- list(
    title = "coeff")

  p <- plot_ly() %>%

    add_lines(x = ~ my_df$factor_level,
              y = ~ my_df$coeff,
              yaxis = primary_y_axis,
              line = list(color = "blue")) %>%

    layout(
      title = "graph",
      xaxis = x_axis,
      yaxis = primary_y_axis)

  p
}

df <- data.frame(factor_level = c("Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"),
                 exposure = c(50, 70, NA, 40, 45, 78, 42, 22, 28, 49, 50, 31),
                 coeff = c(1.1, 1.2, NA, 1.3, 1.8, 1.6, 1.4, 1.3, 1.2, 1.1, 1.5, 1.3))

my_levels = c("Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces")

df$factor_level <- factor(df$factor_level, levels = my_levels)

my_fav_graph_SO(df, my_levels)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM