首页 > 解决方案 > 如何生成窄ggplot图

问题描述

我必须关注数据

conv.lan_graph_data <- structure(list(`Spoken Languages` = c("Arabic", "Cantonese", 
"English", "French", "German", "Hindi", "Japanese", "Korean", 
"Mandarin", "Other", "Persian / Farsi", "Prefer not to answer", 
"Punjabi", "Russian", "Spanish", "Tagalog", "Urdu", "Vietnamese"
), n = c(7L, 45L, 191L, 2L, 1L, 3L, 3L, 29L, 98L, 15L, 26L, 6L, 
13L, 7L, 7L, 10L, 5L, 4L), conv_lang = structure(c(8L, 16L, 18L, 
2L, 1L, 3L, 4L, 15L, 17L, 13L, 14L, 7L, 12L, 9L, 10L, 11L, 6L, 
5L), .Label = c("German", "French", "Hindi", "Japanese", "Vietnamese", 
"Urdu", "Prefer not to answer", "Arabic", "Russian", "Spanish", 
"Tagalog", "Punjabi", "Other", "Persian / Farsi", "Korean", "Cantonese", 
"Mandarin", "English", "Indigenous languages"), class = "factor")), row.names = c(NA, 
-18L), groups = structure(list(`Spoken Languages` = c("Arabic", 
"Cantonese", "English", "French", "German", "Hindi", "Japanese", 
"Korean", "Mandarin", "Other", "Persian / Farsi", "Prefer not to answer", 
"Punjabi", "Russian", "Spanish", "Tagalog", "Urdu", "Vietnamese"
), .rows = list(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
    12L, 13L, 14L, 15L, 16L, 17L, 18L)), row.names = c(NA, -18L
), class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"))

我不会绘制一个类似于进度报告的非常窄的图表

conv.lan_graph_data %>%  mutate( Percent = paste0(round(n/sum(conv.lan_graph_data$n)*100,1),"%")) %>% ungroup() %>% 
    ggplot() +
    aes(y = "", x = n, fill = conv_lang, label=Percent) +
    geom_col(position="fill", width = 0.1) +
    scale_x_continuous(labels = scales::percent_format(accuracy = 1),
                       expand = c(0, 0),
                       breaks = seq(0, 1, by = 0.10)) +
    scale_y_discrete(expand=c(0,0)) +
    theme(axis.title.y=element_blank(), 
          axis.title.x=element_blank(),
          axis.text.y=element_blank(), 
          axis.ticks.y=element_blank()) +

    theme(legend.position = "none")

但是,我制作的图很宽,我想让它变窄。我尝试使用 c oord_fixed but I don't get the desired outcome在此处输入图像描述 在降价块中设置绘图大小也不是一个选项,因为我使用另一个图表来绘制之后

标签: rggplot2

解决方案


推荐阅读