HISTOGRAM

classic Classic list List threaded Threaded
5 messages Options
New
Reply | Threaded
Open this post in threaded view
|

HISTOGRAM

New
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
______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: HISTOGRAM

Rui Barradas
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
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: HISTOGRAM

Rick Bilonick-5
In reply to this post by New
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 <[hidden email]> 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
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>
> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&amp;data=02%7C01%7Crab45%40pitt.edu%7C55f2571738b246f9dc1e08d646739b27%7C9ef9f489e0a04eeb87cc3a526112fd0d%7C1%7C0%7C636773859721875419&amp;sdata=haHuxll2%2FO0Dci0fSpd0evjfi0MTmLi0JoghvHxlz3o%3D&amp;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&amp;data=02%7C01%7Crab45%40pitt.edu%7C55f2571738b246f9dc1e08d646739b27%7C9ef9f489e0a04eeb87cc3a526112fd0d%7C1%7C0%7C636773859721875419&amp;sdata=aL6arSyKx4m9LBdOMhdhSpsdJmGCHubfdI%2Fns4Rgytw%3D&amp;reserved=0
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: HISTOGRAM

Jim Lemon-4
In reply to this post by New
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 <[hidden email]> 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
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
New
Reply | Threaded
Open this post in threaded view
|

Re: HISTOGRAM

New
In reply to this post by New
Rui Barradas,
thank you for your prompt response, your code will be useful to me in
the future!

Rick Bilonick ("your data appear to be categorical"),
thank you very much for your comment (I would have to more correctly
express my task).

JIM Lemon,
THANKS!!! THIS IS EXACTLY what I needed!

______________________________________________
[hidden email] 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.