注释的字体大小

时间:2018-04-05 09:31:46

标签: r annotations plotly

我做了我的可视化。一切都很好,我使用注释添加一个图例标题,只是我希望标题有一个稍大的字体。

我粘贴在一个自包含的示例下面。任何人都可以告诉我如何微调#34;销售地点"?

的字体
library(tidyverse)
library(plotly)
library(pander)


df1 <- structure(list(year = c(2009L, 2010L, 2011L, 2012L, 2013L, 2014L, 
2015L, 2016L, 2009L, 2010L, 2011L, 2012L, 2013L, 2014L, 2015L, 
2016L, 2009L, 2010L, 2011L, 2012L, 2013L, 2014L, 2015L, 2016L
), sales = c("Extra EU28", "Extra EU28", "Extra EU28", "Extra EU28", 
"Extra EU28", "Extra EU28", "Extra EU28", "Extra EU28", "EU27", 
"EU27", "EU27", "EU27", "EU27", "EU27", "EU27", "EU27", "UK", 
"UK", "UK", "UK", "UK", "UK", "UK", "UK"), value = c(307291L, 
430688L, 483915L, 600302L, 635004L, 596056L, 589990L, 651232L, 
518325L, 613219L, 683995L, 631424L, 615276L, 645861L, 703329L, 
778710L, 254019L, 337912L, 278370L, 326557L, 326080L, 341547L, 
369812L, 376858L)), row.names = c(NA, -24L), .Names = c("year", 
"sales", "value"), class = c("tbl_df", "tbl", "data.frame"))

legendtitle <- list(yref='paper',xref="paper",y=.65,x=1.1, text="Place of    Sale"  ,  showarrow=F) 


p1 <- plot_ly(df1 , x = ~year, y = ~value, color = ~sales, linetype = ~sales,
          symbol=~sales,   marker = list(size = 10),  colors = "Set1",
          type = 'scatter',
          mode = 'lines+markers'              ) %>%  layout( yaxis =      list(rangemode = "tozero",title = "Number of Eggs",
 titlefont=list(size=18)),
xaxis = list(title = "Year", titlefont=list(size=18))) %>%     layout(title="Eggs Produced in the UK", titlefont=list(size=24), annotations=legendtitle)%>% layout( margin = list( t=40, pad=1)) %>%  layout(legend = list(x = 1, y = 0.5))


htmlwidgets::saveWidget(p1, "eggs_plot.html")

1 个答案:

答案 0 :(得分:1)

只需将相应的属性添加到注释对象:

legendtitle <- list(yref='paper',xref="paper",y=.65,x=1.2, 
                    text="Place of Sale",  showarrow=F, 
                    font = list(size = 24)) 

请参阅here