我发现了这个问题,但答案不是最新的,无法产生正确的结果。
如何绘制双 y 轴图?
df <- data.frame(MediaDate = as.Date(c("2016-04-01","2016-05-01","2016-06-01"), format = "%Y-%m-%d"),
Spend = c(39654, 34446, 27402),
Visits = c(19970, 14450, 12419))
plot_ly(df, x = ~MediaDate, y = ~Spend, type = "bar", name = "Spend") %>%
add_trace(x = ~MediaDate, y = ~Visits, mode = "lines", yaxis = "y2", name = "Visits") %>%
layout(yaxis2 = list(overlaying = "y", side = "right"))
Run Code Online (Sandbox Code Playgroud)
生产:
我需要什么(但不是一条条和一条线,而是两行):
在我的 flexdashboard 中,我使用“plotly”库来绘制图表。当数据刷新时,条形尺寸会减小。当时,当我单击“自动缩放”选项时,它工作正常。我的问题是我们可以通过plotly.r代码中的任何选项自动启用自动缩放吗?
我正在使用可视化水平条形图plot_ly()。不显示 x 轴的轴线,但显示 y 轴的轴线。我不确定如何隐藏条形图的轴线。
使用的数据框如下:
df <- data.frame("Grade" = c(9,10,11,12), "totalHours" = c(93,81,7,96),
"Count" = c(30,16,1,14), "average" = c(3.100,5.062,7.000,6.857))
Run Code Online (Sandbox Code Playgroud)
用于可视化的调用plot_ly()如下:
plot_ly(df, x=df$average, y=df$Grade,
type="bar", color=~Grade, orientation = 'h') %>%
add_text(text=round(df$average), hoverinfo='none', textposition = 'auto', showlegend = FALSE,
textfont=list(size=12, color="black")) %>%
layout(yaxis = list(showgrid = FALSE),showlegend=FALSE)
Run Code Online (Sandbox Code Playgroud)
有什么解决办法吗?
我正在 R 中的绘图中添加一个变量选择器(遵循通常的方法,即隐藏图中不必要的痕迹)
\n\nlibrary(plotly)\n\ndat <- mtcars\ndat$cyl <- factor(dat$cyl)\ndat$car <- rownames(mtcars)\n\ndat %>% \n plot_ly(x = ~car, y = ~mpg,\n name=\'mpg\', type=\'scatter\', mode=\'markers\') %>%\n add_trace(y = ~hp, name = \'hp\', type=\'scatter\', mode=\'markers\') %>%\n add_trace(y = ~qsec, name = \'qsec\', type=\'scatter\', mode=\'markers\') %>%\n layout(\n updatemenus = list(\n list(\n type = "list",\n label = \'Category\',\n buttons = list(\n list(method = "restyle",\n args = list(\'visible\', c(TRUE, FALSE, FALSE)),\n label = "mpg"),\n list(method = "restyle",\n args = list(\'visible\', c(FALSE, TRUE, FALSE)),\n label = "hp"),\n list(method …Run Code Online (Sandbox Code Playgroud) 我正在努力寻找一种方法,可以在情节中加粗我的饼图标签。有谁知道如何将情节饼图的标签加粗?这是我的代码:
t <- list(
family = "Ariel",
size = 15,
color = 'black')
fig <-plot_ly()
#####Fall/Winter Concentration
fig <-fig%>% add_pie(concWDper,
labels = concWDper$Compounds,
values = concWDper$Concentration,
type = 'pie',
sort = FALSE,
textinfo = '',
textfont = list(color = '#000000'),
marker = list(colors = c("#9E0142", "#D53E4F",
"#F46D43","#FDAE61", "#FEE08B", "#FFFFBF", "#E6F598",
"#ABDDA4", "#66C2A5", "#3288BD", "#5E4FA2")),
domain = list(x = c(0, 0.5), y = c(0.75, 1)))
#####Spring/Summer Concentration
fig <-fig%>% add_pie(concSPDper, labels = concSPDper$Compounds,
values = concSPDper$Concentration, type = 'pie',sort = FALSE, …Run Code Online (Sandbox Code Playgroud) 那里!我尝试使用“plotly”包来使我的生存曲线具有交互性,因此对于可重复的示例,我使用“lung”数据集:
library(survival)
library(survminer)
library(plotly)
sf_lung <- survival::survfit(survival::Surv(time, status) ~ 1, data = lung)
p1 <- ggsurvplot(sf_lung, main = "Kaplan-Meier Curve for the NCCTG Lung Cancer Data")
plotly::ggplotly(p1)
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
UseMethod("ggplotly", p) 中的错误:没有适用于 'ggplotly' 的方法应用于类“c('ggsurvplot', 'ggsurv', 'list')”的对象
那么有什么问题吗?
我的会话信息:
R 版本 4.0.2 (2020-06-22){...}
其他附加软件包:
surviviner_3.2-7 survminer_0.4.8 ggpubr_0.4.0plotly_4.9.2.1 ggplot2_3.3.2
我正在绘制散点图,ggplot()如下所示:
library(data.table)
library(plotly)
library(ggplot2)
library(lubridate)
dt.allData <- data.table(date = seq(as.Date('2020-01-01'), by = '1 day', length.out = 365),
DE = rnorm(365, 4, 1), Austria = rnorm(365, 10, 2),
Czechia = rnorm(365, 1, 2), check.names = FALSE)
## Calculate Pearson correlation coefficient: ##
corrCoeff <- cor(dt.allData$Austria, dt.allData$DE, method = "pearson", use = "complete.obs")
corrCoeff <- round(corrCoeff, digits = 2)
## Linear regression function extraction by creating linear model: ##
regLine <- lm(DE ~ Austria, data = dt.allData)
## Extract k …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置 3D 曲面图的相机,使 x 轴从左 = 0 到右 = 60,y 轴从下 = 0 到上 = 80,同时 z 轴位于左侧。
有一个例子:
library(plotly)
library(magrittr)
plot_ly(z = ~volcano) %>%
add_surface() %>%
layout(scene = list(camera=list()))
Run Code Online (Sandbox Code Playgroud)
我尝试更改函数中的x、y和参数,但没有成功。我也尝试使用。zeye()xasix = list(autoarante = "reversed")
我想plotly基于我的数据中的一列离散值来过滤使用创建的图表.最终目标是能够使用按钮来更新过滤器值,因此我不想事先过滤数据.
library(plotly)
df <- data.frame(group1 = rep(c('low', 'high'), each = 25),
x = rep(1:5, each = 5),
group2 = letters[1:5],
y = c(runif(25, 0, 2), runif(25, 3, 5)))
plot_ly(df, x = ~x, y = ~y, type = 'scatter',
mode = 'line',
color = ~group2,
transforms = list(
list(
type = 'filter',
target = ~group1,
operation = '=',
value = 'high'
)
)
)
Run Code Online (Sandbox Code Playgroud)
我希望这会给出以下图表:
但相反它给出了这个:
它似乎是在错误的变量上过滤.为什么不按照我预期的方式过滤数据?
运行我的代码时收到以下错误:
plot_ly(data, x = ~RighttoWork_NonRtw,
y = ~market_value_level_unfunded_liability,
text = ~paste("State: ", state,
"Market Value Level Unfunded Liability", market_value_level_unfunded_liability),
color = ~market_value_level_unfunded_liability,
size = ~market_value_level_unfunded_liability,
type = "scatter")
Run Code Online (Sandbox Code Playgroud)
未指定分散模式:将模式设置为标记阅读有关此属性的更多信息 -> https://plot.ly/r/reference/#scatter-mode 错误:
size/width值必须为数字。
为什么会这样?
我试图根据无资金准备的负债变量数字获得一系列具有不同大小点的情节点。不幸的是,我不断收到此错误消息。