简体   繁体   English

R提高图表日志轴的可读性

[英]R improve chart log axis readability

i am actually stuck at improving readability of my charts (you can see sample of them below), 实际上,我一直坚持提高图表的可读性(您可以在下面查看其中的示例),

i have more than 15 charts with various x-axis a and y-axis lenght, both of them are logarithmic. 我有超过15个图表,其中x轴a和y轴长度各不相同,它们都是对数的。 Main problem (as you can see on that sample chart) is density of labels at x-axis and sparse ticks at y-axis. 主要问题(在该样本图上可以看到)是x轴上的标签密度和y轴上的稀疏刻度。

Ticks are defined by following line ad hoc for each chart: 刻度是通过以下每个图表的临时行定义的:

scale_x_log10(breaks = c(1, seq(10,10000,10))) + scale_y_log10(breaks = c(1, seq(500,10000,500)))

but as it is totally obvious, it cannot handle my request to place ticks "to not overwhelm and also not to be so sparse". 但完全显而易见的是,它无法处理我的要求,“不要使人不知所措,也不要如此稀疏”。 If i define labels param in any other way than ticks, ggplot throws an error ("Breaks and labels have unequal lengths"). 如果我用除刻度之外的任何其他方式定义标签参数,则ggplot会引发错误(“中断和标签的长度不相等”)。

Is there any way how to improve this log scale labeling? 有什么方法可以改善这种对数刻度标签吗?

Thank you very much in advance 提前非常感谢你

x轴和y轴稀疏

Data + code: 数据+代码:

title1= "NM_001271428_1"
x1= c(1,2,3,4.5,8.5,12,15.5,22.5,34.5,44.5,54,70.5,93.5,124.5,164,205.5,257.5,327,405.5,497.5,583.5,665.5,761.5,858)
y1= c(50,78,75,103.5,178.5,240,294.5,405,586.5,712,810,987,1215.5,1494,1804,2055,2317.5,2616,2838.5,2985,2917.5,2662,2284.5,1716)
title2= "NR_034168_1"
x2= c(1,3,14.5,67)
y2= c(10,12,43.5,134)
title3= "NM_000016_4"
x3= c(1,2,3,4,5,6,9,12,16,25,39.5,63.5,97,142,210.5,326.5,512)
y3= c(19,36,51,60,70,78,108,132,160,225,316,444.5,582,710,842,979.5,1024)
title4= "NM_004672_3"
x4= c(1,2,3,4,5.5,8,10.5,13,15.5,18,22,27.5,35.5,43.5,53.5,65,79,104,136.5,173,209.5,253.5,313,402.5,508.5,630)
y4= c(32,54,75,96,126.5,176,220.5,260,294.5,324,374,440,532.5,609,695.5,780,869,1040,1228.5,1384,1466.5,1521,1565,1610,1525.5,1260)
title5= "NM_006243_3"
x5= c(1,2,3,5.5,10,19.5,36.5,60,92,128,193,304,444.5,607.5)
y5= c(22,28,39,66,110,195,328.5,480,644,768,965,1216,1333.5,1215)
title6= "NM_198460_2"
x6= c(1.5,3,4.5,6.5,10,13.5,16,20.5,29,41.5,63,90.5,128.5,187,261,346,446,543,636.5,731)
y6= c(40.5,63,85.5,117,170,216,240,287,377,498,693,905,1156.5,1496,1827,2076,2230,2172,1909.5,1462)
title7= "NM_001024212_1"
x7= c(1,3,6,11.5,30.5,89)
y7= c(53,18,30,46,91.5,178)
title8= "NM_001040196_1"
x8= c(1,2,4,10,19.5,32,62.5,129.5,250.5)
y8= c(14,20,32,70,117,160,250,388.5,501)
title9= "NM_001122681_1"
x9= c(1,2,3,4.5,6,7,8,9,10.5,12,13,15,18.5,23.5,31,39,44.5,54,64.5,72.5,82,91.5,100.5,111.5,132.5,161.5,192,219.5,257,307,352,401,463,530,596.5,668,741.5,819,893)
y9= c(93,86,123,175.5,222,252,280,306,346.5,384,403,450,536.5,634.5,806,975,1068,1242,1419,1522.5,1640,1738.5,1809,1895.5,2120,2422.5,2688,2853.5,3084,3377,3520,3609,3704,3710,3579,3340,2966,2457,1786)
title10= "NM_001137552_1"
x10= c(1,2,3,4,5.5,7,8,9,12,17.5,21.5,25,32.5,43,56,77,101.5,133.5,194,267.5,345.5,453.5,582.5,726)
y10= c(69,52,75,96,121,147,160,171,216,280,322.5,350,422.5,516,616,770,913.5,1068,1358,1605,1727.5,1814,1747.5,1452)
title11= "NM_001166109_1"
x11= c(1,2,3,4.5,6.5,10,16.5,23,33.5,47,63,90.5,135,191,258,338.5,430,529.5,640,758.5)
y11= c(31,42,60,81,110.5,160,247.5,322,435.5,564,693,905,1215,1528,1806,2031,2150,2118,1920,1517)

p<- ggplot() + 
    xlab('r') + ylab('k') + ggtitle('5-Gram') + labs(color='Text', shape='Text') +
geom_line(aes(x1, y1, color=title1)) + geom_point(aes(x1, y1, color=title1, shape=title1)) +
#geom_line(aes(x2, y2, color=title2)) + geom_point(aes(x2, y2, color=title2, shape=title2)) +
geom_line(aes(x3, y3, color=title3)) + geom_point(aes(x3, y3, color=title3, shape=title3)) +
geom_line(aes(x4, y4, color=title4)) + geom_point(aes(x4, y4, color=title4, shape=title4)) +
geom_line(aes(x5, y5, color=title5)) + geom_point(aes(x5, y5, color=title5, shape=title5)) +
geom_line(aes(x6, y6, color=title6)) + geom_point(aes(x6, y6, color=title6, shape=title6)) +
#geom_line(aes(x7, y7, color=title7)) + geom_point(aes(x7, y7, color=title7, shape=title7)) +
geom_line(aes(x8, y8, color=title8)) + geom_point(aes(x8, y8, color=title8, shape=title8)) +
#geom_line(aes(x9, y9, color=title9)) + geom_point(aes(x9, y9, color=title9, shape=title9)) +
#geom_line(aes(x10, y10, color=title10)) + geom_point(aes(x10, y10, color=title10, shape=title10)) +
#geom_line(aes(x11, y11, color=title11)) + geom_point(aes(x11, y11, color=title11, shape=title11)) +
scale_x_log10(breaks = c(1, seq(10,10000,10))) + scale_y_log10(breaks = c(1, seq(500,10000,500))) +
geom_point(size=3) + 
theme_bw()
p

You can check this answer and apply to x axis: 您可以检查此答案并将其应用于x轴:

ggplot2 y-axis ticks not showing up on a log scale ggplot2 y轴刻度未显示在对数刻度上

Bests, ZP Best,ZP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM