在ggplot2中显示每第n个行名 [英] Show every nth row name in ggplot2
本文介绍了在ggplot2中显示每第n个行名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个采用以下长格式的数据框:
I have a dataframe in the following long format:
> 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
每种方法都有2196个观测值.我正在这样绘制它:
Each method has 2,196 observations. I'm plotting it like this:
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行名称?
I've blocked out the rows because they overlap each other and make a mess. Is there a way to show every 100th row name? Or every 200th row name?
推荐答案
下面是显示轴上所有其他因子水平的示例.似乎是一个非常糟糕的主意...
Here's an example of displaying every other factor level in an axis. Seems like a really bad idea though...
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)])
这篇关于在ggplot2中显示每第n个行名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文