改变R绘图中注释的字体大小。

问题描述 投票:0回答:1

我想增加plotly图上文字注释的大小。我想出的解决方案是下面的最小代码。但是,一旦通过数值增加数字的数量,文字的字体大小就不能以同样的方式应用到所有数字成员中。为了向大家展示实际问题,我准备了一个伪输入数据,所以请大家不要把注意力集中在为什么有一些愚蠢的数字要显示上。这个问题看起来是个小问题,但它严重影响了我的波动数据可视化,这些数据在序列中有各种深层和顶部的值。有什么办法吗?

最少的代码

library(plotly)

df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv", stringsAsFactors = FALSE)
df <- df[which(df$year==2007 & df$continent=='Europe' & df$pop > 2.e6),]

#pseudo input data
temp_data <- c(c(1:5, 10:15, 100:105, 1000:1010))

fig <- plot_ly(df, type='bar', x = ~country, y = temp_data, text = temp_data, name="",
               textposition = 'outside', #'auto' 
               textangle    = -90,
               textfont     = list(size = 120)
               )

fig

电流输出

enter image description here

期望是这样的

enter image description here

r graphics annotations font-size r-plotly
1个回答
1
投票

你可以通过使用 layout. 为了适应这些数字,我还增加了y轴的范围。

library(plotly)
#> Loading required package: ggplot2
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout

df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv", stringsAsFactors = FALSE)
df <- df[which(df$year==2007 & df$continent=='Europe' & df$pop > 2.e6),]

#pseudo input data
temp_data <- c(c(1:5, 10:15, 100:105, 1000:1010))

fig <- plot_ly(df, type='bar', x = ~country, y = temp_data, text = temp_data, name="",
               textposition = 'outside', #'auto'
               textangle    = -90) %>% layout(yaxis=list(range=c(0, max(temp_data)+200)),
                                              uniformtext=list(minsize=18, mode='show'))
fig

创建于2020-05-27,由 重读包 (v0.3.0)

© www.soinside.com 2019 - 2024. All rights reserved.