With str_wrap(), the fct_reorder can't work

I use one public datasets for plot.

x1 <- data.frame( 
  primary  = c("結腸、直腸、乙狀結腸連結部及肛門", "肝及肝內膽管", "肺、支氣管及氣管", "口腔、口咽及下咽", "攝護腺",   "食道", "胃", "皮膚", "膀胱", "白血病"),
 number = c(9434 ,7800, 7936, 7058, 5866, 2563, 2304, 2089, 1707, 1383),
 gender  = rep("M",10))

# reorder the  primary with number
x1 <- x1 %>% mutate(primary = fct_reorder(primary, number))

ggplot(x1, aes(primary, number)) +
geom_col(color ="blue") +
geom_text(aes(label = number)) +


The names of item on x-axis is too long; thus I use str_wrap as suggested

ggplot(x1, aes(str_wrap(primary, 8), number)) +
geom_col(color ="blue") +
geom_text(aes(label = number)) +

The names become beautiful, but the order of columns is out

I google it and read the suggested topic by system. I can not find the way to solve it. I hope someone can help me. Thanks a lot.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.