Hello all, I'm trying to make a histogram of the data contained in my dataframe. The summary of the data gives me exactly what I want summary (Data) V1 V2 first001: 3 last001: 9 first002: 3 last002: 7 first003: 2 last003: 6 (Other) :52 (Other): 27 But how do I capture the names and values in vectors so I can plot them?
What about? hist(Data$V1) hist(Data$V2) Cheers, Josh On Mon, Oct 24, 2011 at 9:38 AM, Joe Carl <joseph.w.carl.jr at gmail.com> wrote:> > Hello all, > > I'm trying to make a histogram of the data contained in my dataframe. > The summary of the data gives me exactly what I want > > summary (Data) > V1 ? ? V2 > first001: 3 ? last001: 9 > first002: 3 ? last002: 7 > first003: 2 ? last003: 6 > (Other) :52 ? ?(Other): 27 > > But how do I capture the names and values in vectors so I can plot them? > > ______________________________________________ > 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.-- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/
Hi: Aren't V1 and V2 factors in this data frame? If so, you should be plotting bar charts rather than histograms (they're not the same). Do you want separate graphs for V1 and V2, do you want them stacked, or do you want them dodged (side-by side for each level 001, 002, 003)? In the absence of such information, it's difficult to tell you how to plot them. Dennis On Mon, Oct 24, 2011 at 9:38 AM, Joe Carl <joseph.w.carl.jr at gmail.com> wrote:> Hello all, > > I'm trying to make a histogram of the data contained in my dataframe. > The summary of the data gives me exactly what I want > > summary (Data) > V1 ? ? V2 > first001: 3 ? last001: 9 > first002: 3 ? last002: 7 > first003: 2 ? last003: 6 > (Other) :52 ? ?(Other): 27 > > But how do I capture the names and values in vectors so I can plot them? > > ______________________________________________ > 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. >
Hi Joe,
What about this? Btw, the real key to a reproducible example is one
that we can actually work with----output of the summary of the data is
not the same as the data itself. That makes it tricky to know what
exactly you are working with (although sometimes the original form of
the data can be intuited from the summary output). For future
reference, providing the output of something like:
dput(head(Names))
would make it easier for us to read your data in, and then we have
exactly what you are working with and can offer advice more easily.
## Read data in
Names <- read.table(textConnection("
V1 V2
1 First001 Last001
2 First002 Last001
3 First003 Last002
4 First004 Last003"), header = TRUE)
closeAllConnections()
# barplots of table()d results
barplot(table(Names$V2))
barplot(table(Names$V2))
Cheers!
Josh
On Mon, Oct 24, 2011 at 11:03 AM, Joe Carl <joseph.w.carl.jr at gmail.com>
wrote:> I thought I did, but I'll restate it again
>
> I have data imported from a file with first and last names
>
>> Names <- read.table("Name.txt", header = FALSE)
>> Names
> ? ? ? ? ? ? ? V1 ? ? ? ? ? ?V2
> 1 ?First001 ?Last001
> 2 ?First002 ?Last001
> 3 ?First003 ?Last002
> 4 ?First004 ?Last003
>
> I can produce a summary of the Names data
>
>> Summary(Names)
>
> ? ? ? ? ? ?V1 ? ? ? ? ? ? ? ? V2
> ?First001: 3 ? Last001: 9
> ?First002: 3 ? Last002: 7
> ?First003: 3 ? Last003: 7
> (Other): 52 ? ?(Other): 27
>
> This summary result contains the quantity of First001 entries ? I want
> this put into a vector along with the quantity so I can actually plot
> it.
>
> the command you gave will not work
>
>>hist(Names$V1)
> Error in hist.default(H02) : 'x' must be numeric
>
> You could try
>>hist(table(Names$V1))
> but it produces the wrong plot
>
> table(Names$V1) is the right stuff
> but the plot produced by hist(Names) is not correct
>
>>hist(Names$V1, plot = FALSE)
> it produces
> $breaks
> [1] 1.0 1.5 2.0 2.5 3.0
>
> $counts
> [1] 34 11 ?0 ?4
>
> $intensities
> [1] 1.3877551 0.4489796 0.0000000 0.1632653
>
> $density
> [1] 1.3877551 0.4489796 0.0000000 0.1632653
>
> $mids
> [1] 1.25 1.75 2.25 2.75
>
> $xname
> [1] "pathways"
>
> $equidist
> [1] TRUE
>
> attr(,"class")
> [1] "histogram"
>
>
>
> Which is all wrong!!!!
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/