标签: plotly

当 R 中只有一条轨迹时,图例未显示在堆积的条形图中

当我在plotly堆积条形图中只添加了一条轨迹时,图例丢失了。

我的数据集如下:

myDF <- structure(list(Year = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "2017", class = "factor"), 
    Month = c("Mar", "Mar", "Mar", "Apr", "Apr", "Apr"), Date = structure(c(17241, 
    17242, 17242, 17259, 17260, 17261), class = "Date"), Quarter = c("Q1", 
    "Q1", "Q1", "Q2", "Q2", "Q2"), Week = structure(c(2L, 2L, 
    2L, 3L, 3L, 3L), .Label = c("2017-03-05", "2017-03-12", "2017-04-02"
    ), class = "factor"), NPS = structure(c(NA, NA, NA, 3L, 3L, 
    3L), .Label = c("Detractor", "Passive", "Promoter"), class = "factor")), …
Run Code Online (Sandbox Code Playgroud)

r plotly

6
推荐指数
1
解决办法
2626
查看次数

仅在单击 Shiny 中的操作按钮后才更新服务器上的内容

我在 R 中闪亮的服务器中遇到反应输出问题。

我想要做的是创建一个使用基于输入计算的值的绘图。

仅在单击提交/完成按钮后才必须更新输出,并且必须根据需要多次计算输出。

我设法做的是独立于提交按钮更新内容(提交按钮根本没有功能),并且在我更改 1 个值后立即更改了绘图。

我想要做的是仅在指定我想要的所有参数值后更改绘图。

这是我的 ui.R 代码的最小示例:

    shinyUI(fluidPage(
      titlePanel("Wages in Year 2016 for Czech Republic in CZK"),
       sidebarPanel(

      conditionalPanel(condition = "input.conditionedPanels==7",
                 selectInput("Age", "Age", choices = vek_mod$Vek, selected = "23-27"),
                 selectInput("ChosenSex", "Your sex", choices = pohlavi_mod$Pohlavie, selected = "Zena"),
                 actionButton("Button", "Done"),
                 p("Click so changes will take effect.")
      ),
        mainPanel(
         tabsetPanel(
           ...
            tabPanel("Minimal_Example", textOutput("Minimal_Example"), value = 7)
            ...
            , id = "conditionedPanels"
    )
   )
  )
 )
Run Code Online (Sandbox Code Playgroud)

这是 server.R 代码:

...
  output$Minimal_Example <- renderPrint({

    Age <- input$Age
    Sex …
Run Code Online (Sandbox Code Playgroud)

r shiny plotly

6
推荐指数
1
解决办法
2947
查看次数

使用小数绘制并以百分比表示工具提示标签

我希望使用 ggplotly 绘制折线图并以百分比表示数字。所以 ggplot 命令之前或代表百分比和之后或小数的数字。情节似乎不同。如何使用小数绘制绘图并以百分比表示工具提示标签?

library(plotly)
library(ggplot2)
library(devtools)
library(proto)
library(RColorBrewer)
library(gapminder)
library(stringr)
library(broom)
library(mnormt)

dat1 <- data.frame(
sex = factor(c("Female","Female","Male","Male")),
time = factor(c("Lunch","Dinner","Lunch","Dinner"), 
levels=c("Lunch","Dinner")),
total_bill = c(13.53, 16.81, 16.24, 17.42)
total_bill_pr = sprintf("%.0f%%", 100 * total_bill)
)

# Map sex to different point shape, and use larger points
p <- ggplot(data=dat1, aes(x=time, y=total_bill_pr, group=sex, shape=sex)) +
geom_line() +
geom_point()

p <- ggplotly(p)
p
Run Code Online (Sandbox Code Playgroud)

或者

 # Map sex to different point shape, and use larger points
p …
Run Code Online (Sandbox Code Playgroud)

r tooltip percentage ggplot2 plotly

6
推荐指数
1
解决办法
967
查看次数

plotly:大量数据点

我正在尝试使用 plotly 绘制具有大量数据点(2mm-3mm)的东西。

当我跑

py.iplot(fig, filename='test plot')
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Woah there! Look at all those points! Due to browser limitations, the Plotly SVG drawing functions have a hard time graphing more than 500k data points for line charts, or 40k points for other types of charts. Here are some suggestions:
(1) Use the `plotly.graph_objs.Scattergl` trace object to generate a WebGl graph.
(2) Trying using the image API to return an image instead of a graph URL
(3) Use matplotlib
(4) See …
Run Code Online (Sandbox Code Playgroud)

python plotly

6
推荐指数
2
解决办法
4572
查看次数

如何从离线 plotly python jupyter notebook 中的选定点获取数据?

示例代码:

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

import plotly.graph_objs as go

import numpy as np

N = 30
random_x = np.random.randn(N)
random_y = np.random.randn(N)

# Create a trace
trace = go.Scatter(
    x = random_x,
    y = random_y,
    mode = 'markers'
)

data = [trace]

# Plot and embed in ipython notebook!
iplot(data, filename='basic-scatter')
Run Code Online (Sandbox Code Playgroud)

[在此处输入图片说明]

如何从选择中获取 x、y 数据或索引的副本?

python plotly jupyter-notebook

6
推荐指数
1
解决办法
1449
查看次数

如何强制 Plot.ly Python 使用给定的 yaxis 范围?

如下所示,我手动定义了每个 yaxis 的范围,并将 autorange 选项设置为 False。

但是,如果您绘制此图,您仍会发现 yaxis1 的范围是 0 到 20,而不是 0 到 25。因此,其中一个条形伸出图表。

我如何才能确定每个值都包含在 yaxis 范围内?

编辑:此外,第二行的顶部网格线未显示。如果我稍微重新缩放,它会再次出现。所以这个问题似乎纯粹是图形化的。任何想法表示赞赏。

from plotly import tools
fig = tools.make_subplots(rows=2, cols=2, subplot_titles=['A', 'B'], shared_xaxes=False, shared_yaxes=True)

data = [[10, 4, 15, 20.5], [3, 12, 22.2], [6.5, 12, 26.2], [18, 4.2, 22.2]]
traces = [go.Bar(x=['Type A', 'Type B', 'Type C'], y=d) for d in data]

fig.append_trace(traces[0], 1, 1)
fig.append_trace(traces[1], 1, 2)
fig.append_trace(traces[2], 2, 1)
fig.append_trace(traces[3], 2, 2)

fig['layout']['yaxis1'].update(title='', range=[0, 25], autorange=False)
fig['layout']['yaxis2'].update(title='', range=[0, 30], autorange=False) …
Run Code Online (Sandbox Code Playgroud)

python-3.x plotly plotly-dash

6
推荐指数
1
解决办法
2万
查看次数

使用 Plotly 在等高线图上叠加线

我想覆盖在顶部的线的Plotly等高线图,类似于覆盖在基质的图像上的线,其中所述强度表示位置z内R3:

# Generate an arbitrary matrix
m <- matrix(sin(1:6^2) * 1:6, nrow = 6)

# Define a path
path <- data.frame(x = c(0:7), y = c(0, 1, 2, 2, 3, 3, 4, 6))

image(x = 1:6, y = 1:6, z = m, col = gray.colors(20), xlab = "x", ylab = "y")
lines(path$x, path$y)
Run Code Online (Sandbox Code Playgroud)

其中呈现:

线和矩阵图

使用 Plotly,我尝试过

library(plotly)
plot_ly(x = 1:6, y = 1:6, z = t(m), type = "contour") %>% 
  add_lines(x = path$x, y = path$y) …
Run Code Online (Sandbox Code Playgroud)

r plotly r-plotly

6
推荐指数
1
解决办法
1364
查看次数

R Plotly:拆分图例:符号和颜色

对于每个数据点“符号”和“名称”,我有一些数据和两个类别。我正在绘制数据并用不同的符号和颜色映射类别,如下所示。

data <- data.frame(
        x= c(1,2,3,4,5,6,7,8),
        y = c(10,11,10,12,11,9,8,13), 
        symbol = c("invalid", "valid", "invalid",
                   "valid", "valid", "valid","valid", "valid"),
        name = c("A", "B", "B", "A", "A", "A", "B", "B"))


plot_ly(data) %>%
add_markers(y = ~y,  x = ~x,  symbol = ~symbol, color = ~name,
            symbols = c(4, 27),
            mode = 'markers',
            #split = ~name,
            colors = c("red", "navy"))
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

传说非常拙劣。

我想将两个图例条目与十字架合并,并为图例中的十字架设置中性颜色,如下所示:

在此处输入图片说明

我尝试使用该split参数,但这没有帮助。

r legend plotly

6
推荐指数
1
解决办法
1187
查看次数

在曲线上将刻度线标签更改为特定字符串

我有plotly图形,我想将轴刻度标记更改为特定字符串.请考虑以下示例:

library(plotly)
p <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

假设我想压缩所有数字xaxis刻度标记,而只是绘制字符串"min"at x = 4.5和"max"at x = 8.

我怎样才能做到这一点plotly?


旁注:我知道这可以用于基础R图,例如此处和ggplot2设置scale_x_continuous(breaks = c(4.5, 8), labels= c("4.5" = "min", "8" = "max")).

还有办法实现这一目标plotly吗?..不幸的是,plotly 文档似乎没有提供解决方案..

r ggplot2 plotly

6
推荐指数
1
解决办法
2017
查看次数

Plot.ly:共享 X 轴的子图的不同高度

背景

  • 具有相同高度 (?) 的不同子图 (?)

我可以创建一个带有共享 X 轴的子图的图形(示例改编自Plot.ly doc),子图之间有适当的分隔,并且您可以通过subplot_titles以下方式为每个子图插入特定标题:

from plotly import tools
import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(
    x=[0, 1, 2],
    y=[10, 11, 12]
)
trace2 = go.Scatter(
    x=[2, 3, 4],
    y=[100, 110, 120],
)
trace3 = go.Scatter(
    x=[3, 4, 5],
    y=[1000, 1100, 1200],
)
fig = tools.make_subplots(rows=3, cols=1, specs=[[{}], [{}], [{}]],
                          shared_xaxes=True, shared_yaxes=True,
                          vertical_spacing=0.1, subplot_titles=('subtitle 1', 
                          'subtitle 2', 'subtitle 3'))
fig.append_trace(trace1, 3, 1)
fig.append_trace(trace2, 2, 1)
fig.append_trace(trace3, …
Run Code Online (Sandbox Code Playgroud)

python plotly plotly-dash

6
推荐指数
1
解决办法
4826
查看次数