ggplot facet_wrap as_labeller не отображает новую последовательность - PullRequest
0 голосов
/ 22 января 2019

Я создал вектор упорядоченных имен и попытался заменить каждый заголовок панели на упорядоченный (например, Джесси с 1. Джесси, Мэрион с 2.Marion и т. Д.).Но вместо этого я получаю АН для каждого заголовка панели.Любые намеки на то, что идет не так.

С NA picture with the NAs

С закомментированным ярлыком picture without with the labeller commented out

list.top.35.names.ordered <- data.frame( cbind(order = c(1:35),list.top.35.names)) %>% 
  unite( name.new, c("order" ,"list.top.35.names"), sep = ".")

  list.top.35.names.ordered <- list.top.35.names.ordered$name.new[1:35]

str (list.top.35.names.ordered)
chr [1:35] "1.Jessie" "2.Marion" "3.Jackie" "4.Alva" "5.Trinidad" "6.Ollie" ...

data.babyname.all %>% 
  ggplot( mapping = aes(x = year, y = perc, fill = sex)) +
  geom_density(stat = "identity", position = "stack" , show.legend = F ) +
  facet_wrap(~name, ncol= 7, nrow =5, labeller= as_labeller(list.top.35.names.ordered)) +
  scale_fill_manual(values = c('#E1AEA1','#9ABACF'))  +
  geom_point(data = most.unisex.year.and.value, mapping = aes(x =  year, y = perc), 
             size = 3, 
             fill = "white", 
             color = "black", 
             shape = 21) +
  scale_y_continuous(breaks = c(0,.50,1), labels= c("0%", "50%","%100")) +
  scale_x_continuous(breaks = c(1940, 1960, 1980,2000), labels= c('1940', "'60","'80",'2000')) +
  geom_text(mapping = aes(x =x , y = y , label = label),  check_overlap = F, na.rm = T, position = position_dodge(width=.9),  size=3) +
  theme_minimal() + #set theme
  theme(
          text = element_text(size = 10),
          axis.title.x = element_blank(),
          axis.title.y = element_blank(),
          panel.grid = element_blank(), 
          panel.border = element_blank(),
          plot.background = element_blank(),
          axis.ticks.x = element_line(color = "black"),
          axis.ticks.length =unit(.2,'cm'),
          strip.text = element_text(size = 10, margin = margin(l=10, b = .1))) 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...