我想在每個 y 軸標簽之間添加空格/邊距,因此這些點不會重疊,但我無法找到解決方案。

生成圖的代碼在這里:
library(tidyverse)
devtools::install_github('danielludolf/FFplot')
library(FFplot)
library(plotly)
p <- data %>%
ggplot(aes(x = `Race/Ethnicity`, y = fct_inorder(Measures)))
labs(x = "", y = "")
geom_point(aes(size = Pixels,
text = paste0(
"Measure: ", str_wrap(Measures, 60), "<br>",
"Disparity: ", str_wrap(`Race/Ethnicity`, 50), "<br>")),
color = '#004c89', stroke = 1)
theme(legend.position = "none")
ff_ggplotly(p, source_name = "Add Source Here", width = 750, height = 550) %>%
layout(yaxis = list(gridcolor = '#d4d4d3'))
我使用的資料集如下:
structure(list(Measures = c("Zero Net Worth", "Zero Net Worth",
"Uninsured", "Uninsured", "Unemployment", "Unemployment", "Poverty",
"Poverty", "Median Employment Income", "Median Employment Income",
"Liquid Asset Poverty", "Liquid Asset Poverty", "Income Insufficiency",
"Income Insufficiency", "Housing Cost Burden (renters)", "Housing Cost Burden (renters)",
"Housing Cost Burden (homeowners)", "Housing Cost Burden (homeowners)",
"Houshold Underbanked Status", "Houshold Underbanked Status",
"Household Banking Status", "Household Banking Status", "Homeownership",
"Homeownership", "Employer-Provided Health Insurance", "Employer-Provided Health Insurance",
"Educational Attainment", "Educational Attainment", "Business Value",
"Business Value", "Asset Poverty", "Asset Poverty"), `Race/Ethnicity` = c("Black/AA, NH :
White, NH",
"Hispanic/Latino : White, NH", "Black/AA, NH : White, NH", "Hispanic/Latino : White, NH",
"Black/AA, NH : White, NH", "Hispanic/Latino : White, NH", "Black/AA, NH : White, NH",
"Hispanic/Latino : White, NH", "Black/AA, NH : White, NH", "Hispanic/Latino : White, NH",
"Black/AA, NH : White, NH", "Hispanic/Latino : White, NH", "Black/AA, NH : White, NH",
"Hispanic/Latino : White, NH", "Black/AA, NH : White, NH", "Hispanic/Latino : White, NH",
"Black/AA, NH : White, NH", "Hispanic/Latino : White, NH", "Black/AA, NH : White, NH",
"Hispanic/Latino : White, NH", "Black/AA, NH : White, NH", "Hispanic/Latino : White, NH",
"Black/AA, NH : White, NH", "Hispanic/Latino : White, NH", "Black/AA, NH : White, NH",
"Hispanic/Latino : White, NH", "Black/AA, NH : White, NH", "Hispanic/Latino : White, NH",
"Black/AA, NH : White, NH", "Hispanic/Latino : White, NH", "Black/AA, NH : White, NH",
"Hispanic/Latino : White, NH"), Pixels = c(35.4, 51.55, 91.4500000000001,
79.1000000000001, 41.8517568812349, 19.0738225897106, 36.451355662209,
84.5353032987158, 41.8689225795901, 52.8685324089523, 14.2245846952017,
7.76867956641282, 13.775217283819, 9.77368755100193, 18.3689239165512,
25.3197416180145, 11.9779708756455, 16.1033936963916, 34.8411564399252,
22.7121030150228, 39.2441860465116, 28.75, 31.1957446808511,
40.8170212765957, 75.4838709677419, 78.5483870967742, 32.075,
42.8416666666667, 21.1139240506329, 26.0443037974683, 20.7666836410461,
33.1868273779831)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-32L))
uj5u.com熱心網友回復:
您可以在函式中使用 amargin在layouty 軸標簽之間創建空間。您可以使用以下代碼:
library(tidyverse)
devtools::install_github('danielludolf/FFplot')
library(FFplot)
library(plotly)
p <- data %>%
ggplot(aes(x = `Race/Ethnicity`, y = fct_inorder(Measures)))
labs(x = "", y = "")
geom_point(aes(size = Pixels,
text = paste0(
"Measure: ", str_wrap(Measures, 60), "<br>",
"Disparity: ", str_wrap(`Race/Ethnicity`, 50), "<br>")),
color = '#004c89', stroke = 1)
theme(legend.position = "none")
ff_ggplotly(p, source_name = "Add Source Here", width = 750, height = 550) %>%
layout(margin = list(l=0, r=0, b=20, t=20, pad=0),
yaxis = list(gridcolor = '#d4d4d3'))
輸出:

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/462276.html
上一篇:展平深度嵌套的資料框串列
