记录并中断y轴(ggplot2)

时间:2018-10-19 16:42:46

标签: r ggplot2

我有这张图

enter image description here

代码:

library("tidyverse")
library("scales")
#data
> dput(Vesself[1:50,])
structure(list(AREA = c("A10", "A13", "A16", "A2", "A23", "A25", 
"A25", "A26", "A26", "A26", "A27", "A28", "A28", "A36", "A39", 
"A43", "B25", "B25", "B26", "B26", "B30", "B30", "B41", "B43", 
"B44", "C27", "C36", "C7", "D15", "D19", "D24", "D29", "D29", 
"D38", "D51", "E15", "E17", "E18", "E18", "E19", "E19", "E19", 
"E19", "E20", "E27", "E27", "E27", "E28", "E28", "E28"), VESSELm = structure(c(5L, 
5L, 5L, 5L, 5L, 3L, 5L, 5L, 3L, 2L, 5L, 3L, 5L, 3L, 5L, 5L, 5L, 
3L, 3L, 5L, 2L, 5L, 5L, 5L, 5L, 5L, 3L, 5L, 3L, 3L, 3L, 3L, 5L, 
3L, 2L, 5L, 3L, 5L, 3L, 1L, 2L, 5L, 3L, 5L, 3L, 2L, 5L, 2L, 3L, 
5L), .Label = c("1", "2", "3", "4", "5"), class = "factor"), 
VESSEL = c(1, 1, 1, 2, 1, 2, 5, 5, 2, 1, 1, 1, 6, 1, 1, 5, 
1, 1, 1, 2, 1, 2, 1, 1, 6, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 
1, 6, 1, 3, 1, 1, 1, 1, 1, 5, 1, 22, 2, 1, 8), Clust = structure(c(4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 4L, 4L, 4L, 4L, 2L, 2L, 
4L, 4L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L), .Label = c("1", "2", "3", "4"), class = "factor")), row.names = c(NA, 
50L), class = "data.frame")

my_breaksx = c(1, 4, 16, 64, 256, 660)

#Plot

ggHist <- ggplot(data = Vesself, aes(VESSEL, color = Clust, fill = Clust)) + geom_bar(stat = "count", width = 0.08) + scale_color_manual(values = cols, name = "Group") + scale_fill_manual(values = cols, name = "Group") +
  scale_x_continuous(trans = log2_trans(), breaks = my_breaksx) +
  labs(x="Density of ships per area", y="Number of area", title="Distribution of ship density", subtitle="by scales")+
  theme_bw() +
  theme(plot.title = element_text(face="bold", hjust=0.5), plot.subtitle=element_text(hjust=0.5), legend.background = element_rect(fill="grey90", size=0.5, linetype="solid", colour ="black"), aspect.ratio = 1) + 
  facet_wrap(~VESSELm)
ggHist

当我尝试将对数转换应用于y轴时,我没有与x轴相同的结果。这些值非常高。我不明白为什么。

没有手动中断的转换结果:

scale_y_continuous(trans = log2_trans())

enter image description here

以及带有手动中断的结果:

my_breaksy = c(1, 4, 16, 64, 150)

scale_y_continuous(trans = log2_trans(), breaks = my_breaksy)

enter image description here

我的目标是具有与x轴等效的表示形式。

0 个答案:

没有答案
相关问题