Re: [R] subject: horizontal text in barplot

From: Marc Schwartz <marc_schwartz_at_comcast.net>
Date: Mon, 02 Jun 2008 08:19:31 -0500

on 06/02/2008 08:00 AM dat wrote:
>
> I have a problem with the ylabs in barplot. When I draw the bars
> horizontal the text for the y axis is not drawn horizontal too.
> The text remains vertical. How can I change that. Thank's for your advice.
> There is an example below.
>
>
> ##Example
> plot.new()
> jib <- data.frame(c(1:15),c(11:25),c(15:1),c(25:11))
> colnames(jib) <- c("eins","zwei","drei","vier")
> rownames(jib) <- c("AT", "BE", "DK", "FI", "FR", "DE",
> "GR", "IE", "IT", "LU", "NL", "PT", "ES", "SE", "UK" )
> jib <- as.matrix(jib)
> jib <- t(jib)
> barplot(jib, horiz=TRUE)
> jib
> ## End Example

A lot of what you are doing above with respect to managing/structuring the example data is not needed, nor is the plot.new().

Here is your jib:

 > jib

      AT BE DK FI FR DE GR IE IT LU NL PT ES SE UK eins 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 zwei 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 drei 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 vier 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11

Now use:

jib2 <- matrix(c(1:15, 11:25, 15:1, 25:11), nrow = 4, byrow = TRUE)

rownames(jib2) <- c("eins", "zwei", "drei", "vier")

colnames(jib2) <- c("AT", "BE", "DK", "FI", "FR", "DE",

                      "GR",    "IE",    "IT",    "LU",    "NL",    "PT",
                      "ES",    "SE", "UK" )

 > jib2
      AT BE DK FI FR DE GR IE IT LU NL PT ES SE UK
eins 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 zwei 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 drei 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 vier 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11

# Now draw the plot, setting 'las' so the labels are # set to horizontal. See ?par for more information

barplot(jib2, horiz = TRUE, las = 1)

Data frames are best used when you have columns with differing data types (think database table or spreadsheet). When the data is of a single type, as in this case, just use a matrix directly.

HTH, Marc Schwartz



R-help_at_r-project.org 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. Received on Mon 02 Jun 2008 - 13:34:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 02 Jun 2008 - 14:30:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive