粗体绘图 (R) 饼图标签

DFM*_*124 2 label r r-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
Run Code Online (Sandbox Code Playgroud)

以下是一些示例数据:https://docs.google.com/spreadsheets/d/1yarGI5ee5ST_uzeQI-Xa2lk681d24vbIurUl6Rj58YY/edit ?usp=sharing

ste*_*fan 5

粗体标签可以通过属性来实现,texttemplate如下所示:

\n

texttemplate = \'<b>%{label}</br></br>%{percent}</b>\'

\n

要调整边距,请使用布局属性margin,例如

\n
margin = list(b = 200, l = 100)\n
Run Code Online (Sandbox Code Playgroud)\n

使用此处的示例数据:

\n
library(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))\n
Run Code Online (Sandbox Code Playgroud)\n

在此输入图像描述

\n

立即编辑您的数据

\n
concWDper <- 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\n
Run Code Online (Sandbox Code Playgroud)\n

在此输入图像描述

\n