本文介绍了自定义图形的x轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我使用 scale_x_discrete()自定义x轴的刻度和标签。然而,如图所示,这些线条切断了右侧的y轴,这对我来说并不好看。你能帮我解决这个问题吗?数据(温度)也显示在下面。 > a = ggplot(data = temp,aes(b,c,group = a,shape = a,color = a),ordered = TRUE)+ geom_line()+ geom_point()> a >标签= c(2,4 ,8,16,32,64,128)) > temp abc 1一个2 5.1 2一个4 6.6 3一个8 7.7 4一个16 8.4 5一个32 16.1 6一个64 38.0 7一个128 49.2 8两个2 5.9 9两个4 7.7 10两个8 9.2 11两个16 10.3 12两个32 16.8 13两个64 32.4 14两个128 45.7 $ b $ 15三个2 4.7 三个4 7.0 17三个8 8.5 18三个16 9.6 19三人32 14.8 20三人64 31.0 21三人128 34.5 22四人2 4.3 23四人4 6.9 24四人8 8.3 25四个16 9.1 26四个32 14.0 27四个64 23.8 解决方案 div> 为什么你使用离散的比例来表示连续的东西。 如果你替换 scale_x_discrete 与 scale_x_continuous 然后这应该是你想要的。 b b 您可能会对基数2的转换感兴趣,因为您的 b 数据只显示给 a + scale_x_continuous(breaks = 2 ^(1:7),trans ='log2') I am using scale_x_discrete() to customize ticks and labels of x-axis.However, as figure shows, the lines cut the right-side y-axis, which doesn't look good to me. Could you please help me to fix this. The data (temp) is also shown below. > a = ggplot(data = temp, aes(b, c, group=a,shape=a,colour=a), ordered=TRUE) + geom_line() + geom_point()> a> b = a + scale_x_discrete(breaks = c("2","4","8","16","32","64","128"), labels=c("2","4","8","16","32","64","128"))> temp a b c1 One 2 5.12 One 4 6.63 One 8 7.74 One 16 8.45 One 32 16.16 One 64 38.07 One 128 49.28 Two 2 5.99 Two 4 7.710 Two 8 9.211 Two 16 10.312 Two 32 16.813 Two 64 32.414 Two 128 45.715 Three 2 4.716 Three 4 7.017 Three 8 8.518 Three 16 9.619 Three 32 14.820 Three 64 31.021 Three 128 34.522 Four 2 4.323 Four 4 6.924 Four 8 8.325 Four 16 9.126 Four 32 14.027 Four 64 23.8 解决方案 Why are you using a discrete scale for something at appears to be continuous.If you replace scale_x_discrete with scale_x_continuous then this should work as you wish.b <- a + scale_x_continuous(breaks = 2^(1:7))bYou might be interested in a transformation to base 2, given the way your data for b appear only to be integer powers of 2.a + scale_x_continuous(breaks = 2^(1:7), trans = 'log2') 这篇关于自定义图形的x轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 16:15