ggplot axis custom order with duplicate labels

后端 未结 2 840
南笙
南笙 2021-01-15 09:10
set.seed(357)
x <- data.frame(name = sample(letters, 10), val = runif(10), stringsAsFactors = F)
x[c(2,6),\"name\"] <- c(\"k\",\"k\")
ggplot(x, aes(x = name, y         


        
相关标签:
2条回答
  • 2021-01-15 09:34

    Actually, simply add the following setting xlab(x$name)

    ggplot(x, aes(x = name, y = val)) + theme_bw() + geom_bar(stat = "identity") + xlab(x$name)
    
    0 讨论(0)
  • 2021-01-15 09:46

    Try this...

    x$name2 <- 1:nrow(x)
    ggplot(x, aes(x = factor(name2), y = val)) + theme_bw() + geom_bar(stat = "identity") + 
                 scale_x_discrete(labels=x$name)
    
    0 讨论(0)
提交回复
热议问题