使用对数刻度时的倒置密度图

时间:2019-03-02 16:48:26

标签: r ggplot2 logarithm density-plot

我尝试使用R的ggplot2来创建密度图,但是,一旦我给scale_y_log10()以获得对数y轴,该图本身就会反转。 如何更正此问题以获得类似于下面所示的预期结果?

观察结果

The error Image that I am getting

预期结果

Actual output Image

我的代码

fd <- read.csv('data.csv')
fd_factor <- factor(fd$XDIndicator, levels = c("a","b","c"), 
                    labels = c("a","b","c"))
p <- ggplot(fd, aes(x = KTotal, fill = factor(fd_factor))) +
    geom_density(alpha = 0.2, na.rm = TRUE) + 
    xlab('Total collaboration degree') + ylab("PDf") + 
    scale_y_log10() 
ggplotly(p)

0 个答案:

没有答案