R ggplot 2:如何显示中断

R ggplot 2:如何显示中断,r,ggplot2,R,Ggplot2,我无法让ggplot2在水平条中显示中断。代码如下: dat <- data.frame( result = c(replicate(50, 'ok'), replicate(17, 'error'), replicate(35, 'notrun')), test = 'test', count = 'count' ) ggplot(data=dat, aes(x=test, y=count, fill=result)) + geom_bar(stat="

我无法让ggplot2在水平条中显示中断。代码如下:

dat <- data.frame(
    result = c(replicate(50, 'ok'), replicate(17, 'error'), replicate(35, 'notrun')),
    test = 'test',
    count = 'count'
)

ggplot(data=dat, aes(x=test, y=count, fill=result)) +
    geom_bar(stat="identity") +
    scale_fill_manual(values = c(ok = '#00BA38', error='#F8766D', notrun='gray')) +
    xlab("") + ylab("") +
    scale_x_discrete(label="") +
    scale_y_discrete(breaks = c(1, 7, 9)) +
    coord_flip()

dat
ggplot
如果您离开
stat=identity
自动计数。在这种情况下,您也可以不使用count变量:

dat <- data.frame(
    result = c( replicate(50, 'ok'), replicate(17, 'error'), 
                replicate(35, 'notrun') ),
    test = 'test' )

ggplot(data=dat, aes(x=test, fill=result)) +
geom_bar() + 
coord_flip() + 
scale_fill_manual(values = c(ok = '#00BA38', error='#F8766D', notrun='gray'))
dat