我有一个数据集,其中包含一名球员与每个队友的传球和接球。示例数据集如下所示:
ter Stegen Pique Rakitic Busquets Coutinho Suarez Messi \
ter Stegen 0 8 0 2 0 1 1
Pique 12 0 2 20 0 0 1
Rakitic 3 3 0 13 5 2 6
Busquets 1 1 9 0 0 0 8
Coutinho 0 0 2 1 0 4 6
Suarez 0 0 2 1 2 0 1
Messi 0 2 5 1 3 4 0
Lenglet 4 6 8 8 1 0 0
Alba 1 1 8 4 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 plotly 在 R 中制作甜甜圈图。我尝试了 ggplot,但它无法给我所需的效果。这是一个示例数据集:
library(dplyr)
testfile <- tibble(personID = 1:10,
status = c("bad", "good", "bad", "bad", "bad", "bad", "bad", "bad", "bad", "good"),
department = c("sales", "sales", "marketing", "sales", "marketing", "management", "management", "sales", "sales", "sales"))
Run Code Online (Sandbox Code Playgroud)
此图表最终会出现在 PowerPoint 中,因此它不需要响应。相反,我需要饼图来说明,而不是滚动它,属于每个状态的百分比和计数。此外,在饼图的中心,我希望它表示“好”类别中的百分比。
这是我到目前为止的代码。它具有无需滚动即可看到的百分比,但没有计数,并且中心没有百分比。
library(plotly)
p <- testfile %>%
group_by(status) %>%
summarize(count = n()) %>%
plot_ly(labels = ~status, values = ~count) %>%
add_pie(hole = 0.6) %>%
layout(title = "Ratio of Good to Bad", showlegend = F,
xaxis = list(showgrid = FALSE, zeroline …Run Code Online (Sandbox Code Playgroud) 我正在制作一个情节,首先在 ggplot 中,然后使其与 ggplotly 交互。
但我需要正确格式化 data.frame 中名为“precio_actual”的当前价格工具提示。
它在工具提示中显示为:1499。
应该是:S/ 1,4900.00。
数据:
dput(tail_tvs)
structure(list(ecommerce = c("wong", "wong", "wong", "wong",
"wong", "wong"), marca = c("sony", "samsung", "sony", "samsung",
"daewoo", "samsung"), producto = c("sony smart tv 55'' 4k uhd kd-55x750f android",
"samsung smart tv curvo 65'' 4k uhd 65nu7300", "sony smart tv 40'' full hd kdl-40w655d linux",
"samsung smart tv 55'' 4k uhd 55mu6103", "daewoo smart tv 43'' full hd l43s780bts",
"samsung …Run Code Online (Sandbox Code Playgroud) 我正在尝试绘制heatmapusingR的plotly包,我希望在其中对 y 轴刻度文本的特定标签具有特定的颜色。
这是一个示例数据集:
set.seed(1)
df <- reshape2::melt(matrix(rnorm(100),10,10,dimnames = list(paste0("G",1:10),paste0("S",1:10))))
Run Code Online (Sandbox Code Playgroud)
这就是我正在尝试的:
library(plotly)
library(dplyr)
plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>%
layout(yaxis=list(title=list(color=c(rep("darkred",5),rep("darkblue",5)))))
Run Code Online (Sandbox Code Playgroud)
改变: yaxis=list(title=list(color=c(rep("darkred",5),rep("darkblue",5))))
到: yaxis=list(title=list(color=list(c(rep("darkred",5),rep("darkblue",5)))))
或者: yaxis=list(title=list(tickcolor=c(rep("darkred",5),rep("darkblue",5))))
或者: yaxis=list(title=list(tickcolor=list(c(rep("darkred",5),rep("darkblue",5)))))
似乎没有帮助。
任何的想法?
我正在尝试根据“Plotly”中的类别和日期的 ID 计数创建多个折线图 我的日期包含三列“日期”、“类别”、“ID”
我现在使用此代码绘制了一条线
b=mdata.groupby(['Date']).count()['ID ']
b=b.sort_index(ascending=True)
xScale = b.index
yScale = b.values
trace =go.Scatter(
x = xScale,
y = yScale,
marker=dict(
color='Red')
)
data2 = [trace]
graphJSON2 = json.dumps(data2, cls=plotly.utils.PlotlyJSONEncoder)
Run Code Online (Sandbox Code Playgroud)
输出图表应该在 X 轴上有日期,在 Y 轴上有 ID 计数和基于类别的多条线
我有一篇 R 博客文章,其中包含一些传单和情节图。我可以width = "100%"在leaflet()函数中进行设置,当我调整浏览器窗口(或在移动设备上查看)大小时,传单地图会改变形状。我已经在 中尝试过相同width = "100%"的方法plot_ly(),但是对于较小的窗口,绘图不会调整大小,并且需要水平滚动。
有任何想法吗?如果有帮助,我正在使用 blogdown/hugo。
我有带有 Country 列的用户数据集,并且想要绘制用户在各个国家/地区的分布图。我将数据集转换为字典,其中键是国家/地区名称,值是国家/地区的频率计数。字典是这样的:
'usa': 139421,
'canada': 21601,
'united kingdom': 18314,
'germany': 17024,
'spain': 13096,
[...]
Run Code Online (Sandbox Code Playgroud)
为了在世界地图上绘制分布,我使用了以下代码:
#Convert to dictionary
counts = users['Country'].value_counts().to_dict()
#Country names
def getList(dict):
return [*dict]
countrs = getList(counts)
#Frequency counts
freqs = list(counts.values())
#Plotting
data = dict(
type = 'choropleth',
colorscale = 'Viridis',
reversescale = True,
locations = countrs,
locationmode = "country names",
z = freqs,
text = users['Country'],
colorbar = {'title' : 'Number of Users'},
)
layout = dict(title = 'Number of Users per Country',
geo …Run Code Online (Sandbox Code Playgroud) 我想将我的图例文本分成两行。这将有助于增加绘图的宽度并减少图例的宽度。但是,当我使用 \n 时,它会被替换为空格。有没有办法将文本分成两行?
import plotly.graph_objs as go
from plotly.offline import plot
import numpy as np
x = np.arange(0, 100)
y = np.random.normal(size=100)
fig = go.Figure()
fig.add_trace(go.Scatter(
name='A very long\nlegend entry',
x=x,
y=y,
showlegend=True,
mode='lines',
line={'color': 'Black'}))
fig.update_layout(
legend={
'x': 1.01,
'y': 0.5})
plot(fig)
Run Code Online (Sandbox Code Playgroud)
我正在使用 Potly Dashboard 构建仪表板。我使用的是深色引导程序主题,因此我不想要白色背景。
但是,我的地图现在看起来像这样:
生成它的代码如下所示:
trace_map = html.Div(
[
dcc.Graph(
id = "map",
figure = go.Figure(
data=go.Choropleth(
locations=code, # Spatial coordinates
z = df.groupby(['month']).sum()['Sales'].astype(int),
locationmode = 'USA-states',
colorscale = 'Reds',
colorbar_title = "USD",
), layout = go.Layout(title = 'The Cities Sold the Most Product',
font = {"size": 9, "color":"White"},
titlefont = {"size": 15, "color":"White"},
geo_scope='usa',
margin={"r":0,"t":40,"l":0,"b":0},
paper_bgcolor='#4E5D6C',
plot_bgcolor='#4E5D6C',
)
)
)
]
)
Run Code Online (Sandbox Code Playgroud)
我试过了paper_bgcolor,plot_bgcolor但无法使它工作。
我使用plotly.js-(basic-dist-min) v1.52.2和angular-plotly.js v1.5.0一个角8项目中。一切正常,唯一的例外是如果我返回“图形对象”,那么来自 getter 的数据数组和布局,网页会冻结。我想这是因为 plotly 经常调用 getter,但我无法检查,因为 devtools 也被冻结了。getter 很简单:
public get chart(): { data: any, layout: any } | null {
const data = computeSomeChartData(); // just one array filter
return { data: [...], layout: {...} }
// return null if no data
}
Run Code Online (Sandbox Code Playgroud)
模板看起来像:
<plotly-plot
[data]="chart.data"
[layout]="chart.layout"
[config]="{ displayModeBar: false }"
[useResizeHandler]="true"
width="100%"
height="100%"
*ngIf="chart !== null"
></plotly-plot>
Run Code Online (Sandbox Code Playgroud)
如何将图表保留为吸气剂,但防止页面冻结?(最好没有超时或类似的东西。)
plotly ×10
r ×4
python ×3
python-3.x ×2
angular ×1
axis-labels ×1
blogdown ×1
charts ×1
choropleth ×1
count ×1
d3.js ×1
dictionary ×1
donut-chart ×1
getter ×1
ggplot2 ×1
heatmap ×1
holoviews ×1
hugo ×1
pandas ×1
plotly.js ×1
r-markdown ×1