R ggplot日志日志比例

时间:2015-09-25 04:31:11

标签: r plot ggplot2 scale

我有一个情节,我想将其转换为日志对数比例。我尝试了不同的解决方案,但没有一个没有创建正确的日志日志。

原始情节看起来像这样 enter image description here

我用这个脚本来绘制它。

plot(ggplot(data=the.table[[i]],aes(x=the.table[[i]]$friends_count,y=the.table[[i]]$degree.in))+
labs(x="Friends Count",y="Degree In")+
       geom_point(color="#56B4E9")+ggtitle(paste(i,"Degree In-Friends Count",collapse="")))

x和y轴上的值之间的差异真的很大,所以我想用log log scale绘制它

enter image description here

我搜索了stcakoverflow以找到解决方案,我改变了这样的脚本。

plot(ggplot(data=the.table[[i]],aes(x=the.table[[i]]$friends_count,y=the.table[[i]]$degree.in))+
         scale_x_log10(limits = c(1, NA), 
                       labels = trans_format("log10", math_format(10^.x)),
                       breaks=trans_breaks("log10", function(x) 10^x, n=6)) +
         scale_y_log10(limits = c(1, NA),
                       labels = trans_format("log10", math_format(10^.x)),
                       breaks=trans_breaks("log10", function(x) 10^x, n=6)) +
         labs(x="Friends Count",y="Degree In")+
       geom_point(color="#56B4E9")+ggtitle(paste(i,"Degree In-Friends Count",collapse="")))

它生成了带有此警告消息的情节:

Warning messages:
1: In scale$trans$trans(x) : NaNs produced
2: Removed 1 rows containing missing values (geom_point).

你有什么建议吗?感谢。

我已根据您的需要提供样本数据:

structure(list(screen_name = structure(c(70L, 29L, 91L, 37L, 
99L, 33L, 46L, 26L, 63L, 48L, 80L, 17L, 15L, 89L, 88L, 82L, 69L, 
77L, 30L, 12L, 58L, 93L, 64L, 65L, 67L, 41L, 62L, 10L, 74L, 76L, 
1L, 9L, 47L, 35L, 24L, 14L, 71L, 72L, 34L, 23L, 39L, 11L, 52L, 
57L, 86L, 22L, 100L, 3L, 2L, 53L, 78L, 36L, 97L, 84L, 90L, 8L, 
45L, 38L, 50L, 55L, 96L, 61L, 13L, 16L, 43L, 60L, 85L, 32L, 20L, 
83L, 66L, 59L, 56L, 94L, 54L, 31L, 73L, 79L, 18L, 44L, 40L, 4L, 
27L, 19L, 92L, 95L, 75L, 21L, 25L, 6L, 28L, 87L, 7L, 51L, 81L, 
68L, 5L, 42L, 49L, 98L), .Label = c("_Anahtar_", "_fani__", "_uzumce", 
"28BeyzaTosun", "2cerkesoglu", "34fuzuli34RT", "abatila", "Adimozr", 
"AforizmaYazar", "ahmetfuadi", "Ak_ekip_rt", "Ak_Ekip_Rte", "ak_parti_tt", 
"AkgenclikBerlin", "AkGercekler", "AkkulisAK", "Akparti_AkRTE", 
"akreperol1955", "AlparslanTurk06", "aozturk70", "asimm4th", 
"ASLAN__5", "AyAzyahu", "bavehayran", "bbulentkayar", "be_yaz_ca", 
"BennKerem", "BerilDeniz77", "bilalardic_", "billpostmus", "bizimmmemleket", 
"BULUT__USTASI", "BurakFBSensoy", "cayelirize", "CicekciKiz_", 
"DobraUzunAdam", "DogrulariYaziyo", "ebaabil", "efendi_insan", 
"Elmanoglu_Drvs", "emre_izmir_", "ErsoyMehmetAkf", "esma_fb_3437", 
"esrefynbsn", "fatihcaglayan25", "favlasanaa", "FenaYazar", "filiz_paker", 
"GabrielAydin", "gonul_insani_", "HanZala32", "holy_sin", "InstagramPlus", 
"IsmetOnc", "KaankutAatay", "kamilekucuker24", "karikatu_r", 
"KemalAta34", "kiliskilis79", "KIRMIZI_BEY4Z_G", "MahirAytekin", 
"MakarnaSos", "MarkGKirshner", "MazlumunFedaisi", "MercanSureyya", 
"MerterSibel", "MoRHoPi", "muhacir1887", "NormanBuffong", "oncevatan81", 
"OrbisTertius3", "osmanlit0runu", "Oyuna_GelmeTR", "ResmiZaytung", 
"rt_liyorum", "RTerdog4n", "RTErdog4n", "Saglam_Iradee", "Sanki_biri", 
"Semih_Kural", "sessiz_ciglik0", "sevdamizzz", "sezerhsn", "siyaset__name", 
"Siyasi_Yazar", "son3er", "Sussam_Olmuyor_", "Telefizyon", "trakyali77", 
"twit_komedyeni", "TwitineGeldim", "uguronal", "ultrasKan1071", 
"yakupaltinoz", "Yazar212", "YEA1453", "Yn1Dunya", "Yobaz_Zeynep", 
"Yobaz4K", "zekibahce"), class = "factor"), degree.in = c(0L, 
0L, 0L, 0L, 3L, 0L, 0L, 35L, 0L, 0L, 12L, 0L, 71L, 0L, 29L, 0L, 
0L, 330L, 0L, 0L, 207L, 0L, 2L, 337L, 0L, 23L, 0L, 113L, 0L, 
112L, 19L, 0L, 0L, 29L, 0L, 0L, 0L, 10L, 13L, 9L, 0L, 0L, 0L, 
0L, 26L, 0L, 185L, 0L, 285L, 0L, 49L, 152L, 0L, 0L, 11L, 96L, 
1324L, 45L, 0L, 0L, 3L, 1110L, 0L, 0L, 38L, 0L, 40L, 0L, 4L, 
7L, 0L, 13L, 103L, 0L, 40L, 65L, 12L, 0L, 0L, 0L, 2L, 0L, 0L, 
0L, 562L, 0L, 0L, 0L, 225L, 0L, 0L, 93L, 0L, 70L, 0L, 0L, 1L, 
0L, 0L, 4L), friends_count = c(549982L, 360141L, 292551L, 264835L, 
192642L, 190477L, 153839L, 127660L, 126163L, 124043L, 115284L, 
113246L, 109422L, 107159L, 105183L, 101006L, 100667L, 99427L, 
98606L, 97909L, 95053L, 94830L, 92558L, 90112L, 89117L, 88388L, 
87969L, 87650L, 86907L, 85422L, 85395L, 84870L, 84747L, 83611L, 
83357L, 82381L, 82227L, 81084L, 80187L, 78807L, 76336L, 76231L, 
73940L, 73840L, 73759L, 73669L, 73324L, 73268L, 72944L, 72806L, 
71729L, 71208L, 70621L, 69982L, 69669L, 69432L, 69391L, 68880L, 
68478L, 67651L, 67514L, 66855L, 66472L, 66396L, 66309L, 65044L, 
64248L, 64038L, 63455L, 63275L, 62500L, 62388L, 61696L, 61212L, 
61154L, 61077L, 60700L, 60487L, 60426L, 60265L, 60264L, 58954L, 
58907L, 58903L, 58671L, 58086L, 57856L, 57793L, 57127L, 56910L, 
56508L, 56506L, 56466L, 56378L, 56343L, 56334L, 56314L, 56169L, 
55864L, 55858L)), .Names = c("screen_name", "degree.in", "friends_count"
), class = "data.frame", row.names = c(NA, -100L))

1 个答案:

答案 0 :(得分:4)

示例数据包含多个degree.in等于零的条目。零的对数是-Inf,有时表示为NA。无论如何,它在情节中不是一个有意义的值。如果您想以对数比例表示,我建议您确保所有数据点都具有正值。

您可以尝试使用例如

绘制相应的数据子集
the.table_pos <- the.table[the.table$degree.in > 0,]