将文本放在图的X轴上 [英] putting text on the X Axis of Graphs
问题描述
我需要绘制一个图表,其中的X值都是名称 - 例如美国各州
和Y值是数字和降序 - 例如,美国各州的人口。
目前,当我使用绘图函数时,绘制了一个图表,但是a)Y值不是以降序排列,b) X轴显示一串升序数字,而不是州名。
感谢您的帮助。
编辑:
我使用R的数据集:state.name和state.area
> state.name
[1]Alabama等
[1] 51609等
我的实际数据非常相似,所以我只是在玩弄这些。
Trial.Group平均心率上置信区间低置信区间
33subj-Male 80 120 70
听起来好像要一个条形图(或者点阵图)。 R中有3种不同的绘图系统;
#有些美国国家数据
数据(州)
dfr < - data.frame(name = state.name,area = state.area)
dfr $ name< - with(dfr,factor(name,levels = name [order(area)]))
ggplot方式
库(ggplot2)
ggplot(dfr,aes(name,area))+ geom_bar()+ coord_flip()
#点阵方式
库(点阵)
条形图(名称〜面积,数据= dfr)
#基本方式
par(las = 1,mar = c (4,7,1,1))
with(dfr,barplot(area,names.arg = name,horiz = TRUE))
编辑:
为了更容易阅读标签,我制作了横条。
I need to plot a graph where the X values are all names -e.g. states of America
and the Y values are numberic and in descending order- e.g. population of the states of America.
Currently, when I use the plot function, it plots a graph but a) The Y values are not in descending order and b) the X Axis displays a bunch of ascending numbers, not the names of the states.
Thanks for the help.
EDIT:
I was using R's data sets: state.name and state.area
>state.name
[1]"Alabama" etc
>state.area
[1] 51609 etc
my actual data is very similar so I was just playing around with those.
Trial.Group Mean Heart Rate Upper Confidence Interval Lower Confidence Interval
33subj-Male 80 120 70
Sounds like you want a barchart (or maybe a dotplot). There are 3 different plotting systems in R; here are solutions in order of preference.
#Some US state data
data(state)
dfr <- data.frame(name = state.name, area = state.area)
dfr$name <- with(dfr, factor(name, levels = name[order(area)]))
#The ggplot way
library(ggplot2)
ggplot(dfr, aes(name, area)) + geom_bar() + coord_flip()
#The lattice way
library(lattice)
barchart(name ~ area, data = dfr)
#The base way
par(las = 1, mar = c(4, 7, 1, 1))
with(dfr, barplot(area, names.arg = name, horiz = TRUE))
EDIT: I made the bars horizontal in order to make it easier to read the labels.
这篇关于将文本放在图的X轴上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!