What would be the correct code (simplest version) (without gplot()) for histogram (with 7 bars), which would include 7 names of bars under the X-axis. The data are: name number ds 6277 lk 24375 ax 46049 dd 70656 az 216544 df 220620 gh 641827 (I'm attaching mydata.r, making with dput.) My attempt is: options(scipen=999) with (mydata, hist(number)) P.S. I can't understand how the column "name" to include in a code
Hello, You probably want a bar plot, not a histogram. old.sci <- options(scipen=999) with(mydata, barplot(number, space = 0, names.arg = name, beside = TRUE)) options(scipen = old.sci) #----------------- mydata <- read.table(text = " name number ds 6277 lk 24375 ax 46049 dd 70656 az 216544 df 220620 gh 641827 ", header = TRUE) mydata Hope this helps, Rui Barradas ?s 18:45 de 09/11/2018, Medic escreveu:> What would be the correct code (simplest version) (without gplot()) > for histogram (with 7 bars), which would include 7 names of bars under > the X-axis. The data are: > > name number > ds 6277 > lk 24375 > ax 46049 > dd 70656 > az 216544 > df 220620 > gh 641827 > > (I'm attaching mydata.r, making with dput.) > > My attempt is: > > options(scipen=999) > with (mydata, hist(number)) > > P.S. I can't understand how the column "name" to include in a code > ______________________________________________ > 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. >
First, a histogram would not be appropriate (your data appear to be categorical - a histogram is for continuous numeric vales) - you would need a bar plot. You should make two vectors (one for the category names and the other for the frequencies) and use the barplot function. On Fri, Nov 9, 2018 at 1:46 PM Medic <mailiPadpost at gmail.com> wrote:> What would be the correct code (simplest version) (without gplot()) > for histogram (with 7 bars), which would include 7 names of bars under > the X-axis. The data are: > > name number > ds 6277 > lk 24375 > ax 46049 > dd 70656 > az 216544 > df 220620 > gh 641827 > > (I'm attaching mydata.r, making with dput.) > > My attempt is: > > options(scipen=999) > with (mydata, hist(number)) > > P.S. I can't understand how the column "name" to include in a code > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=02%7C01%7Crab45%40pitt.edu%7C55f2571738b246f9dc1e08d646739b27%7C9ef9f489e0a04eeb87cc3a526112fd0d%7C1%7C0%7C636773859721875419&sdata=haHuxll2%2FO0Dci0fSpd0evjfi0MTmLi0JoghvHxlz3o%3D&reserved=0 > PLEASE do read the posting guide > https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.R-project.org%2Fposting-guide.html&data=02%7C01%7Crab45%40pitt.edu%7C55f2571738b246f9dc1e08d646739b27%7C9ef9f489e0a04eeb87cc3a526112fd0d%7C1%7C0%7C636773859721875419&sdata=aL6arSyKx4m9LBdOMhdhSpsdJmGCHubfdI%2Fns4Rgytw%3D&reserved=0 > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Hi Medic, Perhaps this: medic_df<-read.table(text="name number ds 6277 lk 24375 ax 46049 dd 70656 az 216544 df 220620 gh 641827", header=TRUE) library(plotrix) options(scipen=10) barp(medic_df$number,names.arg=medic_df$name,width=0.5) As others have noted, this is really a barplot with no spaces between the bars. Jim On Sat, Nov 10, 2018 at 5:46 AM Medic <mailiPadpost at gmail.com> wrote:> > What would be the correct code (simplest version) (without gplot()) > for histogram (with 7 bars), which would include 7 names of bars under > the X-axis. The data are: > > name number > ds 6277 > lk 24375 > ax 46049 > dd 70656 > az 216544 > df 220620 > gh 641827 > > (I'm attaching mydata.r, making with dput.) > > My attempt is: > > options(scipen=999) > with (mydata, hist(number)) > > P.S. I can't understand how the column "name" to include in a code > ______________________________________________ > 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.