看一下此处的第三个示例(在“添加自定义文本和注释”部分中)。如果放大图表,您可以看到该示例在日期上插入了一条垂直线'2007-12-01'。如果该日期是交易日(例如'2007-11-29'),人们会看到垂直线穿过当天烛台的中间。
我想在两个日期之间绘制一条垂直线(例如 11 月 29 日到 11 月 30 日之间 - 上例中 v 线之前的两个烛台)。我怎样才能做到这一点?
在 R 中,如何为所有绘图设置默认调色板?我知道plot_ly()您可以设置colors=palette,但这仅适用于散点图,不适用于线图。对于线图,您必须单独设置每条迹线的颜色。
我希望能够为当用户从绘图上的模式栏中选择“下载为 png”时创建的 ggplotly 图像指定文件名和尺寸。

我看到有一种方法可以从这里提出的绘图中做到这一点,但希望有来自 ggplotly 图表的类似控制,类似于这里提出的问题。
使用相同的代码示例:
x <- c(1:15)
y <- c(1:15)
xy <- as.data.frame(cbind(x, y))
example <- ggplot(data = xy, aes(x = x, y = y)) + geom_line()
ggplotly(example) %>% config(displaylogo = FALSE,
modeBarButtonsToRemove = c(
'sendDataToCloud',
'autoScale2d',
'resetScale2d',
'hoverClosestCartesian',
'hoverCompareCartesian'
))
Run Code Online (Sandbox Code Playgroud)
我可以利用另一个config setting来指定文件名/属性吗?downloadImage 设置具有文件名、宽度和高度,但我不确定来自 ggplot 时如何访问这些内容。我发现的配置设置列表似乎没有任何我可以重新调整用途的内容。
能够指定文件名和尺寸将非常有帮助,这样我的网站的用户就可以更轻松、更一致地下载图像。此外,向这些下载的图像添加时间戳/文本信息的能力将更加出色。
我试图以绘图方式覆盖折线图和条形图(用一条垂直线指定重要日期),但我遇到了这个问题,其中两条零线偏移而不是在同一条线上。我尝试过摆弄overlaying = 'y'其中的选项layout,并尝试更改三个组件的顺序trace,但似乎没有任何帮助。有什么想法如何修复吗?下面是我的带有虚拟数据的代码:
(此外,如果您能解决我的图例重叠 y2axis 问题,还可获得奖励积分)
date <- seq(as.Date("2015/6/1"), by = "month", length.out = 19)
wires_mnth <- c(rep(0,8),100000,750000,1200000,2500000,3100000,5500000,7500000,8000000,9900000,11300000,11000000)
wires_cnt <- c(rep(0,8),100,200,250,325,475,600,750,800,1000,1150,1200)
data <- data.frame(date, wires_mnth)
plot_ly(data) %>%
add_trace(x = ~date, y = ~wires_cnt, type = 'bar', name = 'Wires Count',
yaxis = 'y2', opacity = .5) %>%
add_trace(x = ~date, y = ~wires_mnth, type = 'scatter', mode = 'lines', name
= 'Monthly Wires') %>%
add_trace(x = c(2016,2016), y = c(0, 12000000), type = 'scatter', …Run Code Online (Sandbox Code Playgroud) 我绘制了价格图表。Y 轴刻度设置为整个价格范围内的最低和最高价格。
当我减小范围时,例如当我显示最后一小时时,Y 轴不会缩放并且给出相同的范围。如何才能使 Y 轴自动缩放到可见的价格范围?
这是我的布局
layout = go.Layout(
title=title,
legend=dict(orientation="h"),
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=1,
label='1h',
step='hour',
stepmode='backward'),
dict(count=3,
label='3h',
step='hour',
stepmode='backward'),
dict(count=6,
label='6h',
step='hour',
stepmode='backward'),
dict(count=1,
label='1d',
step='day',
stepmode='backward'),
dict(count=3,
label='3d',
step='day',
stepmode='backward'),
dict(step='all')
])
),
rangeslider=dict(),
type='date'
),
yaxis=dict(
title=y_axis_label,
showticklabels= not seperate_y_axis,
autorange=True,
type='linear'
)
)Run Code Online (Sandbox Code Playgroud)
我希望交互式(这意味着可以通过框/套索选择来选择它们)抖动点显示在分组箱线图上。我提出了这个问题:Add jitter to boxplot usingmarkers inplotly。我想要完全相同,但箱线图应该分组。
我做了一个箱线图,但要点都混淆了:
dat %>%
plot_ly(x = ~as.numeric(IC),
y = ~xval,
color = ~gene,
type = "box",
hoverinfo = "none",
boxpoints = FALSE
) %>%
add_markers(x = ~jitter(as.numeric(IC)),
y = ~xval,
color = ~gene,
marker = list(size = 3),
hoverinfo = "text",
text = txt,
showlegend = TRUE) %>%
layout(boxmode = "group")
Run Code Online (Sandbox Code Playgroud)
当我尝试按因子对 X 轴进行分组(以便每个组合都是一个级别)时,我无法对箱线图进行分组:
dat <- dat %>%
mutate(gene_x_covariate = as.factor(
paste0(get(facet_title), "-", gene)))
dat %>%
plot_ly(x …Run Code Online (Sandbox Code Playgroud) 我在 server.R 中有以下代码:
library(shiny)
library(plotly)
art.data <- read.csv("data1.csv", stringsAsFactors = FALSE)
shinyServer(function(input, output) {
output$distPlot <- renderPlotly({
col.str <- paste0(input$colspa, ".", input$rgbchoice, ".median")
p <- ggplot(art.data, aes(x = year, y = art.data[[col.str]], text = paste0(artist, "<br>", art))) + geom_point(size = 1) + xlab("Year") + stat_smooth(method = loess, se = FALSE)
ggplotly(p , tooltip = "text")
})
})
Run Code Online (Sandbox Code Playgroud)
如果我删除工具提示,则回归线出现在输出图中,但包含工具提示后,回归线不会出现在图中。有什么解决方案可以将两者结合在一起吗?
我正在尝试使用破折号和绘图生成散点图框,当我在标记内指定符号(例如“正方形”)时,生成地图时它不会呈现。我正在使用回调函数,并且尝试了几个符号,但没有一个有效,但圆圈标记除外。我是否缺少一些明显的东西?这是一个最小的示例,要运行它,您将需要一个 Mapbox 令牌。
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import datetime as dt
app = dash.Dash()
mapbox_access_token = 'YOUR_MAPBOX_TOKEN_HERE'
app.layout = html.Div(children=[
html.H1('Dashboard'),
dcc.DatePickerRange(id='fecha',
start_date=dt.datetime.today() - dt.timedelta(days=30),
end_date=dt.datetime.today()
),
html.Center(dcc.Graph(
id='mapa',
figure={
'data': [
go.Scattermapbox(
lat=[],
lon=[],
)
],
'layout': go.Layout(
autosize=False,
width=1300,
height=800,
hovermode='closest',
showlegend=False,
mapbox=dict(
accesstoken=mapbox_access_token,
bearing=0,
center=dict(
lat=-32,
lon=-70
),
pitch=0,
zoom=5,
),
)
})
,)
])
@app.callback(
dash.dependencies.Output('mapa', 'figure'),
[dash.dependencies.Input('fecha', 'start_date'),
dash.dependencies.Input('fecha', 'end_date')
])
def update_graph(inicio,fin):
Data = …Run Code Online (Sandbox Code Playgroud) 我通过在 2 个窗口子图中绘制数据,能够在一组 4 个数据集之间切换每个图。每个数据集具有不同数量的迹线,并且迹线具有不同的长度名称。这是我的布局定义:
var layout = {
font: {
family:'Roboto',
size: 12,
color: 'rgb(54, 54, 54)'
},
yaxis: {title: "Temperature [C]",
domain: [0,.49],
mirror:'ticks',
showline:true,
linecolor: 'rgb(54, 54, 54)',
ticklen:3,
tickcolor: 'rgb(245, 245, 245)',
linewidth: 1}, // set the y axis title
yaxis2: {title: "Pressure [bara]",
domain: [.51,1],
mirror:'ticks',
showline:true,
linecolor: 'rgb(54, 54, 54)',
linewidth: 1,
ticklen:3,
tickcolor: 'rgb(245, 245, 245)'},
xaxis: {title: "Time (your current local time)",
mirror:'ticks',
showline:true,
linecolor: 'rgb(54, 54, 54)',
linewidth: 1,
tickformat: "%H:%M" …Run Code Online (Sandbox Code Playgroud) 我想将 Plotly 图表渲染器添加到rpivotTable()R 包rpivotTable中的函数中。我按照Javascript 数据透视表Wiki中给出的说明添加可选的额外渲染器。不幸的是,遵循这些说明将导致默认行为。也许我将 Java 代码分配给了错误的参数。
这是一个小例子:
library(rpivotTable)
library(shiny)
server <- function(input, output){
output$mypivot = renderRpivotTable({
rpivotTable(
Titanic,
renderers = htmlwidgets::JS("$.extend($.pivotUtilities.renderers,
$.pivotUtilities.plotly_renderers)"),
rendererName = "Horizontal Stacked Bar Chart"
)
})
}
ui <- shinyUI(fluidPage(
tags$head(tags$script(src = "https://cdn.plot.ly/plotly-latest.min.js")),
rpivotTableOutput("mypivot"))
)
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud) plotly ×10
r ×6
python ×3
ggplot2 ×2
javascript ×2
boxplot ×1
charts ×1
ggplotly ×1
graph ×1
jitter ×1
marker ×1
plotly-dash ×1
rpivottable ×1
shiny ×1
symbols ×1