如何使情节标签清晰

时间:2018-08-06 12:38:37

标签: r ggplot2

我做了一个曲线图,解释了许多变量的每种模态的发生。 关于聚类问题,以显示哪些变量在解释每个聚类。 所以

> dput(DATA1[1:20,])
structure(list(TYPE_PEAU = structure(c(1L, 2L, 1L, 3L, 1L, 2L, 
1L, 2L, 2L, 2L, 3L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L), .Label = c("Sèche", 
"Mixte", "Normale", "Grasse"), class = "factor"), SENSIBILITE = structure(c(2L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 1L, 2L, 2L, 3L, 3L, 3L, 
1L, 3L, 1L), .Label = c("Aucune", "Fréquente", "Occasionnelle"
), class = "factor"), IMPERFECTIONS = structure(c(2L, 2L, 3L, 
2L, 3L, 1L, 2L, 2L, 1L, 2L, 2L, 3L, 2L, 1L, 2L, 2L, 2L, 3L, 2L, 
3L), .Label = c("Fréquente", "Occasionnelle", "Rares"), class = "factor"), 
    BRILLANCE = structure(c(3L, 3L, 1L, 1L, 1L, 2L, 1L, 3L, 3L, 
    3L, 3L, 1L, 3L, 3L, 3L, 3L, 1L, 1L, 3L, 3L), .Label = c("Aucune", 
    "Partout", "Zone T"), class = "factor"), GRAIN_PEAU = structure(c(1L, 
    2L, 1L, 2L, 2L, 3L, 3L, 3L, 3L, 2L, 1L, 2L, 3L, 2L, 2L, 2L, 
    2L, 2L, 2L, 1L), .Label = c("Fin", "Moyen", "Dilaté"), class = "factor"), 
    RIDES_VISAGE = structure(c(3L, 3L, 3L, 3L, 3L, 1L, 1L, 2L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 3L, 3L, 3L), .Label = c("Aucune", 
    "Très visibles", "Visibles"), class = "factor"), ALLERGIES = structure(c(1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L), .Label = c("Non", "Oui"), class = "factor"), 
    MAINS = structure(c(1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 3L, 2L, 
    2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L), .Label = c("Sèches", 
    "Normales", "Moites"), class = "factor"), PEAU_CORPS = structure(c(3L, 
    2L, 2L, 2L, 2L, 1L, 2L, 2L, 3L, 1L, 2L, 2L, 2L, 3L, 2L, 3L, 
    2L, 3L, 3L, 1L), .Label = c("Normale", "Sèche", "Très sèche"
    ), class = "factor"), INTERET_ALIM_NATURELLE = structure(c(3L, 
    1L, 1L, 1L, 1L, 2L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L), .Label = c("Beaucoup", "Pas du tout", "Un peu"
    ), class = "factor"), INTERET_ORIGINE_GEO = structure(c(3L, 
    1L, 1L, 1L, 3L, 2L, 3L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 1L, 1L, 
    3L, 1L, 1L, 1L), .Label = c("Beaucoup", "Pas du tout", "Un peu"
    ), class = "factor"), INTERET_VACANCES = structure(c(1L, 
    1L, 2L, 2L, 3L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 
    1L, 1L, 2L, 2L), .Label = c("À la mer", "À la montagne", 
    "En ville"), class = "factor"), INTERET_ENVIRONNEMENT = structure(c(3L, 
    1L, 1L, 1L, 3L, 2L, 3L, 3L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L), .Label = c("Beaucoup", "Pas du tout", "Un peu"
    ), class = "factor"), INTERET_COMPOSITION = structure(c(3L, 
    1L, 1L, 1L, 1L, 3L, 3L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L), .Label = c("Beaucoup", "Pas du tout", "Un peu"
    ), class = "factor"), PRIORITE_1 = structure(c(1L, 1L, 1L, 
    1L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 1L, 1L, 1L, 1L, 3L, 2L, 2L, 
    3L, 1L), .Label = c("éclatante", "hydratée", "lisse", "matifiée", 
    "nourrie", "purifiée", "reposée"), class = "factor"), MILIEU_RESIDENCE = structure(c(1L, 
    1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 
    2L, 2L, 1L, 2L), .Label = c("nature", "urbain"), class = "factor")), .Names = c("TYPE_PEAU", 
"SENSIBILITE", "IMPERFECTIONS", "BRILLANCE", "GRAIN_PEAU", "RIDES_VISAGE", 
"ALLERGIES", "MAINS", "PEAU_CORPS", "INTERET_ALIM_NATURELLE", 
"INTERET_ORIGINE_GEO", "INTERET_VACANCES", "INTERET_ENVIRONNEMENT", 
"INTERET_COMPOSITION", "PRIORITE_1", "MILIEU_RESIDENCE"), row.names = c(1L, 
2L, 11L, 13L, 15L, 16L, 17L, 20L, 23L, 32L, 33L, 34L, 37L, 38L, 
39L, 40L, 42L, 43L, 45L, 48L), class = "data.frame") 

然后我使用以下代码:

library(tidyverse)
DATA1 %>% 
  gather(k, v) %>% 
  ggplot(aes(v)) + 
  geom_bar(fill = "orange", width = 0.7) + 
  coord_flip() + 
  facet_wrap(~k)

然后我得到这个图:

enter image description here

但是正如您所看到的,纵轴上的横梁并不清晰!

请问如何解决此问题?

1 个答案:

答案 0 :(得分:1)

您可以尝试调整文本大小:

DATA1 %>% 
  gather(k, v) %>% 
  ggplot(aes(v)) + 
  geom_bar(fill = "orange", width = 0.7) + 
  theme(axis.text.y = element_text(face="bold", color="black",  size=4)) +
  coord_flip() + 
  facet_wrap(~k)

和/或将标签缩写为:

 + scale_x_discrete(labels = abbreviate)