粗体图 (R) 饼图标签
Bold plotly (R) pie chart labels
我正在努力寻找一种方法,使我的饼图标签在情节中加粗。有谁知道如何加粗 plotly 饼图的标签?这是我的代码:
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,
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.5, 1), y = c(0.75, 1)))
fig <-fig %>%layout(font=t,showlegend = T,
grid=list(rows=3, columns=2),
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
fig
下面是一些示例数据:https://docs.google.com/spreadsheets/d/1yarGI5ee5ST_uzeQI-Xa2lk681d24vbIurUl6Rj58YY/edit?usp=sharing
粗体标签可以通过属性 texttemplate
实现,如下所示:
texttemplate = '<b>%{label}</br></br>%{percent}</b>'
要调整边距,请使用布局属性 margin
,例如
margin = list(b = 200, l = 100)
使用来自 here 的示例数据:
library(plotly)
USPersonalExpenditure <- data.frame("Categorie"=rownames(USPersonalExpenditure), USPersonalExpenditure)
data <- USPersonalExpenditure[,c('Categorie', 'X1960')]
p <- plot_ly(data, labels = ~Categorie, values = ~X1960, type = 'pie',sort = FALSE,
textinfo = 'label+percent',
texttemplate = '<b>%{label}</br></br>%{percent}</b>',
textfont = list(color = '#000000'),
marker = list(colors = c("#9E0142", "#D53E4F", "#F46D43", "#FDAE61", "#FEE08B",
"#FFFFBF","#E6F598", "#ABDDA4", "#66C2A5", "#3288BD", "#5E4FA2")))
t <- list(
family = "Times New Roman",
size = 15,
color = 'black')
p %>% layout(font=t, margin = list(b = 200, l = 100))
编辑现在你的数据
concWDper <- read.table(text = "Concentration Compounds
42 α-pinene
10 β-pinene
5 β-phellandrene
13 camphene
12 limonene
3 tricyclene
2 fenchene
2 thujene
7 cymene
4 sabinene
1 myrcene", header = TRUE)
t <- list(
family = "Ariel",
size = 15,
color = 'black')
library(plotly)
fig <- plot_ly()
#####Fall/Winter Concentration
fig <-fig%>% add_pie(concWDper,
labels = concWDper$Compounds,
values = concWDper$Concentration,
type = 'pie',
sort = FALSE,
textinfo = '',
texttemplate = '<b>%{percent}</b>',
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)))
fig <-fig%>% add_pie(data = concWDper,
labels = concWDper$Compounds,
values = concWDper$Concentration, type = 'pie',sort = FALSE,
textinfo = '',
texttemplate = '<b>%{percent}</b>',
textfont = list(color = '#000000'),
marker = list(colors = c("#9E0142", "#D53E4F", "#F46D43",
"#FDAE61", "#FEE08B", "#FFFFBF", "#E6F598", "#ABDDA4", "#66C2A5", "#3288BD", "#5E4FA2")),
domain = list(x = c(0.5, 1), y = c(0.75, 1)))
fig <-fig %>%layout(font=t,showlegend = T,
grid=list(rows=3, columns=2),
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
fig
我正在努力寻找一种方法,使我的饼图标签在情节中加粗。有谁知道如何加粗 plotly 饼图的标签?这是我的代码:
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,
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.5, 1), y = c(0.75, 1)))
fig <-fig %>%layout(font=t,showlegend = T,
grid=list(rows=3, columns=2),
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
fig
下面是一些示例数据:https://docs.google.com/spreadsheets/d/1yarGI5ee5ST_uzeQI-Xa2lk681d24vbIurUl6Rj58YY/edit?usp=sharing
粗体标签可以通过属性 texttemplate
实现,如下所示:
texttemplate = '<b>%{label}</br></br>%{percent}</b>'
要调整边距,请使用布局属性 margin
,例如
margin = list(b = 200, l = 100)
使用来自 here 的示例数据:
library(plotly)
USPersonalExpenditure <- data.frame("Categorie"=rownames(USPersonalExpenditure), USPersonalExpenditure)
data <- USPersonalExpenditure[,c('Categorie', 'X1960')]
p <- plot_ly(data, labels = ~Categorie, values = ~X1960, type = 'pie',sort = FALSE,
textinfo = 'label+percent',
texttemplate = '<b>%{label}</br></br>%{percent}</b>',
textfont = list(color = '#000000'),
marker = list(colors = c("#9E0142", "#D53E4F", "#F46D43", "#FDAE61", "#FEE08B",
"#FFFFBF","#E6F598", "#ABDDA4", "#66C2A5", "#3288BD", "#5E4FA2")))
t <- list(
family = "Times New Roman",
size = 15,
color = 'black')
p %>% layout(font=t, margin = list(b = 200, l = 100))
编辑现在你的数据
concWDper <- read.table(text = "Concentration Compounds
42 α-pinene
10 β-pinene
5 β-phellandrene
13 camphene
12 limonene
3 tricyclene
2 fenchene
2 thujene
7 cymene
4 sabinene
1 myrcene", header = TRUE)
t <- list(
family = "Ariel",
size = 15,
color = 'black')
library(plotly)
fig <- plot_ly()
#####Fall/Winter Concentration
fig <-fig%>% add_pie(concWDper,
labels = concWDper$Compounds,
values = concWDper$Concentration,
type = 'pie',
sort = FALSE,
textinfo = '',
texttemplate = '<b>%{percent}</b>',
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)))
fig <-fig%>% add_pie(data = concWDper,
labels = concWDper$Compounds,
values = concWDper$Concentration, type = 'pie',sort = FALSE,
textinfo = '',
texttemplate = '<b>%{percent}</b>',
textfont = list(color = '#000000'),
marker = list(colors = c("#9E0142", "#D53E4F", "#F46D43",
"#FDAE61", "#FEE08B", "#FFFFBF", "#E6F598", "#ABDDA4", "#66C2A5", "#3288BD", "#5E4FA2")),
domain = list(x = c(0.5, 1), y = c(0.75, 1)))
fig <-fig %>%layout(font=t,showlegend = T,
grid=list(rows=3, columns=2),
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
fig