有一个博客条目描述了从图形API嵌入R到R降价.我只是使用代码为html文档创建iframe
当我在R studio中有prieview时,没有错误消息,并且在html文档中创建了iframe.但是,它只是空的.显然它不会以某种方式加载内容.我之前没有在R API中创建绘图(但这不应该重要,因为这只是将图片嵌入到html中)不是吗?
我目前在r markdown中的代码
```{r}
library("knitr")
library("devtools")
url<-"https://plot.ly/~etpinard/251"
plotly_iframe <- paste("<iframe scrolling='no' seamless='seamless' src='", url,
"/800/600' width='800' height='600'></iframe>", sep = "")
```
`r I(plotly_iframe)`
Run Code Online (Sandbox Code Playgroud) 有没有办法在使用R和ggplot2绘图时编码hovermode?
目前,我的代码是:
plot <- ggplot(data, aes(var1, var2, text=var3)) +
geom_point()
py$ggplotly(plot)
Run Code Online (Sandbox Code Playgroud)
我希望绘图图自动将悬停模式设置为"在悬停时显示最接近的数据"而不是"比较悬停时的数据".
假设我想显示一组条形图,其中每个条形图可以是其中一个选项:A,B或C,每个条形图都有不同的颜色.我想显示条形图,但如果条形图属于特定类别,则仍然会在图例中显示该类别.不幸的是,没有颜色的类别似乎被丢弃了.请注意,在此示例中,如何从图例中删除标记为"C"的类别为蓝色的类别:
data = [
{
x: [1, 3, 4],
y: [20, 14, 23],
type: 'bar',
name: 'A',
marker: {color: '#00FFFF'}},
{
x: [2, 5, 6],
y: [8, 6, 2],
type: 'bar',
name: 'B',
marker: {color: '#FF00FF'}},
{
x: [],
y: [],
type: 'bar',
name: 'C'
marker: {color: '#FF0000'}}]
Run Code Online (Sandbox Code Playgroud)
我怎样才能确保C(或任何没有数据的颜色)始终显示?
我想改变我的情节三维散点图的默认摄像机视角,从帮助中不清楚这应该如何完成.我知道布局参数应该包含在命名列表中,但不能让它适用于'眼''上'和'中'相机参数.
https://plot.ly/r/reference/#layout-scene-camera
它应该是这样的:
require(plotly)
scene=list(bgcolor='#990055',camera=list(eye=c(1,2,3)))
plot_ly(x=rnorm(100), y=rnorm(100), z=rnorm(100),
type="scatter3d", mode='markers+lines') %>% layout(scene=scene)
Run Code Online (Sandbox Code Playgroud) ggplotly使用ggplot删除geom_line图的图例.
见下图:
library(plotly)
g <- ggplot(iris)
g = g + geom_line(aes(x = Sepal.Length, y = Sepal.Width, color = Species), size = 0.05)
g # Here is a legend
(gg <- ggplotly(g)) # Legend has now been removed.
Run Code Online (Sandbox Code Playgroud)
任何想法如何取回传奇?
我使用的是plotly_2.0.19和ggplot2_2.0.0.9000.
我从这里运行代码:
import plotly
import plotly.plotly as py
from plotly.tools import FigureFactory as FF
import numpy as np
import pandas as pd
print(plotly.__version__)
dataframe = pd.DataFrame(np.random.randn(100, 3),
columns=['Column A', 'Column B', 'Column C'])
fig = FF.create_scatterplotmatrix(dataframe, diag='histogram', index='Column A',
colormap=['rgb(100, 150, 255)', '#F0963C', 'rgb(51, 255, 153)'],
colormap_type='seq', height=800, width=800)
py.iplot(fig, filename = 'Custom Sequential Colormap')
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 /Users/mona/PycharmProjects/PythonCodes/plotly_viz.py
1.12.4
This is the format of your plot grid:
[ (1,1) x1,y1 ] [ (1,2) x2,y2 ]
[ (2,1) x3,y3 ] …Run Code Online (Sandbox Code Playgroud) 我试图在阴谋中并排获得两个甜甜圈.但是,我只得到一张图片.关于我缺少的任何建议?
library(dplyr)
library(plotly)
df1 <- as.data.frame(matrix(data = c("a","b", "c", 34,28, 29), nrow = 3, ncol = 2))
colnames(df1) <- c("category", "count")
df2 <- as.data.frame(matrix(data = c("Q","F", "G", 29,50, 76), nrow = 3, ncol = 2))
colnames(df2) <- c("group", "count")
p <- subplot(
plot_ly(df1, labels = category, values = count, type = "pie", hole = 0.6, showlegend = TRUE),
plot_ly(df2, labels = group, values = count, type = "pie", hole = 0.6, showlegend = TRUE),
margin = 0.05,
nrows = 2 …Run Code Online (Sandbox Code Playgroud) 这是数据帧
df = pd.DataFrame({"col_1":[0.00143,0.00653,0.00732],"col_2":[0.00984,0.00192,0.00751]},index=['A','B','C'])
Run Code Online (Sandbox Code Playgroud)
这是我的阴谋代码:
trace0 = go.Bar(
x=[df.columns[0],df.columns[1]],
y=[df.ix[0,0],df.ix[0,1]],
name=df.index[0],
# marker=dict(color=cof_pal[0]
)
trace1 = go.Bar(
x=[df.columns[0],df.columns[1]],
y=[df.ix[1,0],df.ix[1,1]],
name=df.index[1],
# marker=dict(color=cof_pal[1]
)
trace2 = go.Bar(
x=[df.columns[0],df.columns[1]],
y=[df.ix[2,0],df.ix[2,1]],
name=df.index[2],
# marker=dict(color=cof_pal[2]
)
layout = go.Layout(showlegend=True, title="Title", font=dict(size=Chart_Title_Font_Size),
yaxis=dict(title='Percentage Change(%)', titlefont=dict(size=yaxis_font_size), tickfont=dict(size=yaxis_font_size)),
xaxis=dict(title='Time', titlefont=dict(size=xaxis_font_size), tickfont=dict(size=yaxis_font_size))
)
data = [trace0,trace1,trace2]
fig = go.Figure(data=data, layout=layout)
iplot(fig, filename='fig1')
Run Code Online (Sandbox Code Playgroud)
我需要y轴为x.xx%格式(或小数点后的n位数).
另一个问题是:y轴标题"百分比变化(%)"太靠近y轴数.如何进一步移动?
我无法获得以下内容来绘制刻度标签
self.months = [2017-01-01', 2017-02-01', ...]
def plot_bar(self):
print self.data
app.layout = html.Div(children=[html.H1(children=''), html.Div(children='Discovered monthly'),
dcc.Graph(
figure=go.Figure(
data = self.data,
layout=go.Layout(
title='Streams', showlegend=True, barmode='stack', margin=go.Margin(l=200, r=0, t=40, b=20),
xaxis=dict(tickvals = self.months, ticktext = self.months, title='months')
)
),
style={'height': 300},
id='my-graph')
])
Run Code Online (Sandbox Code Playgroud)
因此,基本上,我有条形图的数字表示形式,但是当我更改刻度值和刻度标签时,这些数字标签消失了,但是我看不到预期的日期。我是否缺少显示这些标签的开关?
我想在地块之间添加空间,但是当我玩边距游戏时,它会重叠或割伤。这是代码:
library(plotly)
plotList <- function(nplots) {
lapply(seq_len(nplots), function(x) plot_ly())
}
s1 <- subplot(plotList(6), nrows = 2, shareX = TRUE, shareY = TRUE)
s2 <- subplot(plotList(2), shareY = TRUE)
p <- subplot(s1, s2, plot_ly(), nrows = 3, margin = 0.04, heights = c(0.6, 0.3, 0.1))
print(p)
Run Code Online (Sandbox Code Playgroud)
我得到这个:
而我希望这样的东西(用油漆完成的图像)在不同子图之间有更大的间距:
我应该怎么做 ?
plotly ×10
r ×6
plot ×3
python ×3
ggplot2 ×2
formatting ×1
hover ×1
html ×1
keyerror ×1
knitr ×1
python-3.x ×1
r-markdown ×1
r-plotly ×1
spacing ×1
subplot ×1