ggplot axis custom order with duplicate labels

后端 未结 2 856
南笙
南笙 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条回答
  •  萌比男神i
    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)
    

提交回复
热议问题