Skip to content
Prev 389285 / 398506 Next

Improve my plot

Hi Rui,

Many thanks but when I copy and paste your R code here below I get 2 error mesages :

##############
h <- c(574,557,544,535,534,532,531,527,526,525,
? ? ? ? 524,520,518,512,507,504,504,489,488,488,
? ? ? ? 487,484,484,474,472,455,444,420)

nms <- c("Fribourg(f)","Valais(d)","Appenzell Rhodes Int?rieures",
? ? ? ? ? "Fribourg(d)","Jura","Schwyz","Schaffhouse","Berne(f)",
? ? ? ? ? "Thurgovie","Valais(f)","Argovie","Appenzell Rhodes Ext?rieures",
? ? ? ? ? "Gen?ve","Zoug","Tessin","Neuch?tel","Vaud","Uri","Nidwald",
? ? ? ? ? "Berne(d)","Zurich","Obwald","Saint-Gall","Soleure","Lucerne",
? ? ? ? ? "Glaris","B?le-Campagne","B?le-Ville")
nms <- factor(nms, levels = nms)

library(ggplot2)

data.frame(height = h, names = nms) |>
? ggplot(aes(names, height)) +
? geom_col(fill = "deepskyblue2") +
? coord_flip() +
? theme_classic() +
? theme(axis.text.y = element_text(face = "italic"))
##############






Le lundi 20 septembre 2021, 21:54:31 UTC+2, Rui Barradas <ruipbarradas at sapo.pt> a ?crit : 





Hello,

With package ggplot2 this is easy.
ggplot2 is meant to work with data in lists or data.frames, so I use the 
new pipe operator to pass the data on to ggplot().


h <- c(574,557,544,535,534,532,531,527,526,525,
? ? ? ? 524,520,518,512,507,504,504,489,488,488,
? ? ? ? 487,484,484,474,472,455,444,420)

nms <- c("Fribourg(f)","Valais(d)","Appenzell Rhodes Int?rieures",
? ? ? ? ? "Fribourg(d)","Jura","Schwyz","Schaffhouse","Berne(f)",
? ? ? ? ? "Thurgovie","Valais(f)","Argovie","Appenzell Rhodes Ext?rieures",
? ? ? ? ? "Gen?ve","Zoug","Tessin","Neuch?tel","Vaud","Uri","Nidwald",
? ? ? ? ? "Berne(d)","Zurich","Obwald","Saint-Gall","Soleure","Lucerne",
? ? ? ? ? "Glaris","B?le-Campagne","B?le-Ville")
nms <- factor(nms, levels = nms)

library(ggplot2)

data.frame(height = h, names = nms) |>
? ggplot(aes(names, height)) +
? geom_col(fill = "deepskyblue2") +
? coord_flip() +
? theme_classic() +
? theme(axis.text.y = element_text(face = "italic"))


Hope this helps,

Rui Barradas


?s 20:24 de 20/09/21, varin sacha via R-help escreveu: