相关疑难解决方法(0)

带有position_stack的抖动文本/标签

请考虑以下data.frame和图表:

library(ggplot2)
library(scales)
df <- data.frame(L=rep(LETTERS[1:2],each=4),
                 l=rep(letters[1:4],2),
                 val=c(96.5,1,2,0.5,48,0.7,0.3,51))
#   L l  val
# 1 A a 96.5
# 2 A b  1.0
# 3 A c  2.0
# 4 A d  0.5
# 5 B a 48.0
# 6 B b  0.7
# 7 B c  0.3
# 8 B d 51.0

ggplot(df,aes(x=L,y=val,fill=l)) +
  geom_bar(stat="identity") +
  geom_text(aes(label=percent(val/100)),position=position_stack(vjust =0.5))
Run Code Online (Sandbox Code Playgroud)

plot1 由于值较小,某些标签难以阅读.我想垂直抖动它们.我知道position_jitter但它似乎与堆叠条形图兼容.

label r bar-chart ggplot2 jitter

12
推荐指数
2
解决办法
866
查看次数

如何在dplyr中将NAs排在第一位?

请考虑以下示例:

require(tibble)
require(dplyr)

set.seed(42)

tbl <- data_frame(id = letters[1:10], val = c(runif(5), NA, runif(4)))

tbl
Run Code Online (Sandbox Code Playgroud)
# A tibble: 10 × 2
      id          val
   <chr>        <dbl>
1      a 0.9148060435
2      b 0.9370754133
3      c 0.2861395348
4      d 0.8304476261
5      e 0.6417455189
6      f           NA
7      g 0.5190959491
8      h 0.7365883146
9      i 0.1346665972
10     j 0.6569922904
Run Code Online (Sandbox Code Playgroud)

我想排序tibbleval,把NA第一个:

tbl %>%
  arrange(val)
Run Code Online (Sandbox Code Playgroud)
# A tibble: 10 × 2
      id          val
   <chr>        <dbl>
1      i 0.1346665972
2      c …
Run Code Online (Sandbox Code Playgroud)

sorting r na dplyr

2
推荐指数
1
解决办法
516
查看次数

标签 统计

r ×2

bar-chart ×1

dplyr ×1

ggplot2 ×1

jitter ×1

label ×1

na ×1

sorting ×1