简体   繁体   English

在并排条形图上调整 y 轴刻度和 x 轴

[英]adjusting y-axis scale and x-axis on side by side barchart

I used the following code to produce a side-by-side bar chart我使用以下代码生成并排条形图

IT=c(0.588, 0.765)
GE=c(0.214, 0.63)
FR=c(0.316, 0.356)
PO=c(0.692,0.793)
UK=c(0.381, 0.757)
NE=c(0.227, 0.62)
GR=c(0.692, 0.902)
HU=c(0.706, 0.698)
SW=c(0.143, 0.493)

# combine two vectors using cbind 
# function
CountryChart=cbind(IT,GE,FR,PO,UK,NE,GR,HU,SW)

# pass this college_data to the 
# barplot
barplot(CountryChart,beside=T) 

and it produce a graph with the correct data, however the y-axis is too short as it only goes from 0 to 0.8 and not to 1. The country labels are also not all displayed on the x-axis.它会生成一个包含正确数据的图表,但是 y 轴太短,因为它只从 0 到 0.8 而不是 1。国家/地区标签也没有全部显示在 x 轴上。 Only four country codes are displayed so I would like to adjust the code so that it would display the code of each country below its bars.只显示四个国家代码,所以我想调整代码,以便在其条形下方显示每个国家的代码。

Here's the graph I was able to produce:这是我能够生成的图表:

在此处输入图像描述

Any idea on what to do to adjust the scale size of y-axis and display all country codes on the x-axis?关于如何调整 y 轴的比例大小并在 x 轴上显示所有国家代码的任何想法?

To get the y axis to go to 1, add ylim = c(0, 1) in the barplot call:要将 y 轴从 go 变为 1,请在barplot调用中添加ylim = c(0, 1)

barplot(CountryChart,beside=T, ylim = c(0, 1)) 

在此处输入图像描述

To make all your countries appear on the x axis, you need to realise that the plot is suppressing some of the labels to prevent them from overlapping.要使您所有的国家都出现在 x 轴上,您需要意识到 plot 正在抑制一些标签以防止它们重叠。 To fix this, you can shrink the x label sizes:要解决此问题,您可以缩小 x label 尺寸:

barplot(CountryChart,beside=T, ylim = c(0, 1), cex.names = 0.75) 

在此处输入图像描述

Or simply drag your plotting window to make it wider:或者简单地拖动绘图 window 使其变宽:

barplot(CountryChart,beside=T, ylim = c(0, 1)) 

在此处输入图像描述

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

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