繁体   English   中英

设置图例和甜甜圈图

[英]Setting a legend and Donut Plot

我与 Plotly 合作,并试图制作一个甜甜圈情节。 下面你可以看到我的数据。

library(plotly)
library(reshape2)
library(dplyr)

df<-data.frame(city=c("NYC-The written history of New York City began with the first European explorer, the Italian Giovanni da Verrazzano in 1524. European settlement began with the Dutch in 1608.",
                      "Seattle-Seattle is a seaport city on the West Coast of the United States. It is the seat of King County, Washington. ",
                      "Boston",
                      "LA",
                      "Miami",
                      "Washington"),
               value=c(100,200,300,400,500,600))

df <-melt(df)

fig<-df %>% 
  plot_ly(labels = ~city, values = ~value)
fig <- fig %>% add_pie(hole = 0.6)
fig <- fig%>% layout(title = "Comparison between of the cities ")

fig

数据有点具体,因为它包含大约 170 个字符的列。 当我制作甜甜圈情节时,由于人物的原因,图例太大,图表太小。 下面你可以看到这个甜甜圈图的样子。

在此处输入图像描述

那么任何人都可以帮助我如何使这个图例更小,图表更大和相同的标题(使用相同的字体)?

您可以在大图例文本中添加一些\n输入并更改font大小,如下所示:

library(plotly)
library(reshape2)
library(dplyr)

df<-data.frame(city=c("NYC-The written history of New York City began with the first European explorer, \n the Italian Giovanni da Verrazzano in 1524. \n European settlement began with the Dutch in 1608.",
                      "Seattle-Seattle is a seaport city on the West Coast of the United States. \n It is the seat of King County, Washington. ",
                      "Boston",
                      "LA",
                      "Miami",
                      "Washington"),
               value=c(100,200,300,400,500,600))

df <-melt(df)

fig<-df %>% 
  plot_ly(labels = ~city, values = ~value)
fig <- fig %>% add_pie(hole = 0.6)
fig <- fig%>% layout(title = "Comparison between of the cities ",
                     legend = list(font=list(size = 7)))

fig

输出:

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM