我正在努力寻找一种方法,可以在情节中加粗我的饼图标签。有谁知道如何将情节饼图的标签加粗?这是我的代码:
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
Run Code Online (Sandbox Code Playgroud)
粗体标签可以通过属性来实现,texttemplate如下所示:
texttemplate = \'<b>%{label}</br></br>%{percent}</b>\'
要调整边距,请使用布局属性margin,例如
margin = list(b = 200, l = 100)\nRun Code Online (Sandbox Code Playgroud)\n使用此处的示例数据:
\nlibrary(plotly)\nUSPersonalExpenditure <- data.frame("Categorie"=rownames(USPersonalExpenditure), USPersonalExpenditure)\ndata <- USPersonalExpenditure[,c(\'Categorie\', \'X1960\')]\n\np <- plot_ly(data, labels = ~Categorie, values = ~X1960, type = \'pie\',sort = FALSE,\n textinfo = \'label+percent\', \n texttemplate = \'<b>%{label}</br></br>%{percent}</b>\', \n textfont = list(color = \'#000000\'),\n marker = list(colors = c("#9E0142", "#D53E4F", "#F46D43", "#FDAE61", "#FEE08B", \n "#FFFFBF","#E6F598", "#ABDDA4", "#66C2A5", "#3288BD", "#5E4FA2")))\n\nt <- list(\n family = "Times New Roman",\n size = 15,\n color = \'black\')\n\np %>% layout(font=t, margin = list(b = 200, l = 100))\nRun Code Online (Sandbox Code Playgroud)\n\n立即编辑您的数据
\nconcWDper <- read.table(text = "Concentration Compounds\n 42 \xce\xb1-pinene\n 10 \xce\xb2-pinene\n 5 \xce\xb2-phellandrene\n 13 camphene\n 12 limonene\n 3 tricyclene\n 2 fenchene\n 2 thujene\n 7 cymene\n 4 sabinene\n 1 myrcene", header = TRUE)\n\nt <- list(\n family = "Ariel",\n size = 15,\n color = \'black\')\n\nlibrary(plotly)\n\nfig <- plot_ly()\n#####Fall/Winter Concentration\nfig <-fig%>% add_pie(concWDper,\n labels = concWDper$Compounds, \n values = concWDper$Concentration, \n type = \'pie\',\n sort = FALSE,\n textinfo = \'\', \n texttemplate = \'<b>%{percent}</b>\',\n textfont = list(color = \'#000000\'),\n marker = list(colors = c("#9E0142", "#D53E4F", \n "#F46D43","#FDAE61", "#FEE08B", "#FFFFBF", "#E6F598", \n "#ABDDA4", "#66C2A5", "#3288BD", "#5E4FA2")),\n domain = list(x = c(0, 0.5), y = c(0.75, 1)))\n\nfig <-fig%>% add_pie(data = concWDper, \n labels = concWDper$Compounds, \n values = concWDper$Concentration, type = \'pie\',sort = FALSE,\n textinfo = \'\', \n texttemplate = \'<b>%{percent}</b>\',\n textfont = list(color = \'#000000\'),\n marker = list(colors = c("#9E0142", "#D53E4F", "#F46D43", \n "#FDAE61", "#FEE08B", "#FFFFBF", "#E6F598", "#ABDDA4", "#66C2A5", "#3288BD", "#5E4FA2")),\n domain = list(x = c(0.5, 1), y = c(0.75, 1)))\n\nfig <-fig %>%layout(font=t,showlegend = T,\n grid=list(rows=3, columns=2),\n xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),\n yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))\n\nfig\nRun Code Online (Sandbox Code Playgroud)\n\n
| 归档时间: |
|
| 查看次数: |
2244 次 |
| 最近记录: |