這可能不是最優雅的方式來做到這一點,但你可以plot
,points
和axis
使用解決全部問題(axis
是主一,它解釋瞭如何改變軸上的標籤):?axis
,?plot
,?points
。
首先請你類似的數據幀,所以我可以證明......
# make a data frame similar to yours
mydf <- data.frame(Name=LETTERS,
Up=sample.int(15,size=26,replace=T),
Down=-sample.int(15,size=26,replace=T))
現在的情節。
# set up a plot: x axis goes from 1 to 26,
# y limit goes from -15 to 15 (picked manually, you can work yours out
# programmatically)
# Disable plotting of axes (axes=FALSE)
# Put in some x and y labels and a plot title (see ?plot...)
plot(0,xlim=c(1,26),ylim=c(-15,15),type='n',
axes=FALSE, # don't draw axis -- we'll put it in later.
xlab='Name',ylab='Change', # x and y labels
main='Ups and Downs') #,frame.plot=T -- try if you like. ?plot.default
# Plot the 'Up' column in green (see ?points)
points(Up~Name,mydf,col='green')
# Plot the 'Down' column in red
points(Down~Name,mydf,col='red')
# ***Draw the x axis, with labels being A-Z
# (type in 'LETTERS' to the prompt to see what they are)
# see also ?axis
axis(1,at=1:26,labels=LETTERS)
# Draw the y axis
axis(2)
調整它,你想:?points
和?par
和?axis
在這方面特別有幫助。
[文檔是你的朋友。閱讀。愛它。使用它。](http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/plot.html) – 2012-02-20 01:02:02
我已閱讀此頁...問題是我的xaxis是文本。 .. – RnD 2012-02-20 01:25:17
@ mathematical.coffe .i將一個csv文件導入到「nba」變量,然後輸入plot(nba [,1],nba [,2])..這不會給我我想要的.. – RnD 2012-02-20 01:52:52