Skip to content

plot

4 messages · XinMeng, Chuck Cleland, John Kane +1 more

#
Hello sir:
a data with 2 columns:
id x
a  1
b  2
c  3

I wanna get such kind of plot:
x: a b c
y:1 2 3

But the plot command doesn't permit string character as x.

How can I get it ?

Thanks a lot !

My best
#
XinMeng wrote:
What sort of plot do you want?  For a barplot() of x with bars labeled
by id you could do this:

df <- data.frame(id = c("a","b","c"), x = 1:3, stringsAsFactors=FALSE)
with(df, barplot(x, names.arg = id))

  
    
#
--- XinMeng <xmeng at capitalbio.com> wrote:

            
It is not clear exactly what kind of a plot you want
but is it something like this?

x <- c("a", "b", "c")
y <- c(1,2,3)
plot(y, axes=F)
axis(1, at=c(1:3), labels= x)
axis(2, at = y, labels=y)
box()
#
You can do something like this for a scatter plot:

x <- c("a","b","c")
y <- c(1,2,3)

xnum <- rep(1:length(x))
plot(x=xnum, y=y, xlab="x", xaxt="n")
axis(side=1, at=xnum, labels=x)

This fakes a numerical axis and suppresses the y-axis labels that you then
draw with the axis function the way that you want them. If you play with the
xnum vector, you can have different spacing of the points in the
x-direction.

Rene

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of XinMeng
Sent: Monday, December 18, 2006 1:03 AM
To: r-help at stat.math.ethz.ch
Subject: [R] plot

Hello sir:
a data with 2 columns:
id x
a  1
b  2
c  3

I wanna get such kind of plot:
x: a b c
y:1 2 3

But the plot command doesn't permit string character as x.

How can I get it ?

Thanks a lot !

My best

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.