在 ggplot2 中显示每第 n 行名称

Show every nth row name in ggplot2

我有以下长格式的数据框:

> head(cleanLongPlotData)
  Structure Method Value       Outcome
1      1A00 X1     1    Clustering
2      1A01 X1     1    Clustering
3      1A02 X1     0 No Clustering
4      1A0U X1     1    Clustering
5      1A0Z X1     1    Clustering
6      1A1M X1     0 No Clustering
> tail(cleanLongPlotData)
      Structure     Method Value       Outcome
12931      4PRN       Z        0 No Clustering
12932      4PRP       Z        0 No Clustering
12933      4PXZ       Z       -1         Blank
12934      4PY0       Z       -1         Blank
12935      4Q3H       Z       -1         Blank
12936      6HBW       Z        1    Clustering

每种方法都有 2,196 个观察值。我是这样画的:

    p1 <- ggplot(cleanLongPlotData, aes(x=Method, y=Structure,fill=Outcome)) + geom_tile()+
   xlab("Method") +
   ylab("Structure")+
   ggtitle("Cluster Results By Structure")+
      theme(axis.line=element_blank(),
            axis.text.y=element_blank(),axis.ticks=element_blank(),
            panel.background=element_blank(),panel.border=element_blank(),
            panel.grid.major=element_blank(),
            panel.grid.minor=element_blank(),plot.background=element_blank())+
      scale_fill_manual(values = c("#F5F5F5","green","blue"))

我已经屏蔽了行,因为它们相互重叠并且弄得一团糟。有没有办法显示每 100 行名称?还是每 200 行名称?

下面是一个在轴中显示所有其他因子水平的示例。虽然这似乎是一个非常糟糕的主意......

df <- data.frame(Method=rep(LETTERS[1:10], each=10),
                 Structure=rep(LETTERS[17:26]), 
                 Outcome=sample(letters[1:5],100,replace=TRUE))
library(ggplot2)
ggp <- ggplot(df, aes(Method, Structure))+geom_tile(aes(fill=Outcome))+coord_fixed()
ggp

lvls <- levels(df$Structure)
ggp + scale_y_discrete(breaks=lvls[seq(1,length(lvls),by=2)])