Dear R-experts, Here below my R code. I would need your help to improve my graph/plot. - The x-axis to be longer not to stop at 500 value - All the name on the y-axis to appear not only a few of them and the name (Fribourg(f), Appenzell Rhodes Int?rieures,...) to appear entire, not to be cut Many thanks. ############## barplot(height=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),names.arg=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"),font.axis=4, horiz=T,col="deepskyblue2",las=2) ############## ? ?
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:> Dear R-experts, > > Here below my R code. I would need your help to improve my graph/plot. > > - The x-axis to be longer not to stop at 500 value > - All the name on the y-axis to appear not only a few of them and the name (Fribourg(f), Appenzell Rhodes Int?rieures,...) to appear entire, not to be cut > > Many thanks. > > ############## > barplot(height=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),names.arg=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"),font.axis=4, horiz=T,col="deepskyblue2",las=2) > ############## > > > > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >
Don't do this! Use a dotchart instead. See the Wikipedia article on dotplots or search. height=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) ## kudos for plotting the sorted results rather than alphabetically. nm <- 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") dotchart(height, nm, col = "blue", main = "Dotcharts Rock") ?dotchart gives you the details and options. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, Sep 20, 2021 at 12:24 PM varin sacha via R-help <r-help at r-project.org> wrote:> > Dear R-experts, > > Here below my R code. I would need your help to improve my graph/plot. > > - The x-axis to be longer not to stop at 500 value > - All the name on the y-axis to appear not only a few of them and the name (Fribourg(f), Appenzell Rhodes Int?rieures,...) to appear entire, not to be cut > > Many thanks. > > ############## > barplot(height=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),names.arg=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"),font.axis=4, horiz=T,col="deepskyblue2",las=2) > ############## > > > > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Hi varin, Not too difficult: par(mar=c(5,13,4,1)) barplot(height=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), names.arg=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"), horiz=TRUE,col="deepskyblue2",las=2,xlim=c(0,650),font.axis=4) With regard to Bert's objection to barplots, you can do the same thing there. Jim On Tue, Sep 21, 2021 at 5:24 AM varin sacha via R-help <r-help at r-project.org> wrote:> > Dear R-experts, > > Here below my R code. I would need your help to improve my graph/plot. > > - The x-axis to be longer not to stop at 500 value > - All the name on the y-axis to appear not only a few of them and the name (Fribourg(f), Appenzell Rhodes Int?rieures,...) to appear entire, not to be cut > > Many thanks. > > ############## > barplot(height=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),names.arg=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"),font.axis=4, horiz=T,col="deepskyblue2",las=2) > ############## > > > > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.