Thanks John.

Yes I do need to aggregate. I was thinking that ggplot would do the
aggregating, but in any event, am now trying this:
n <- data.frame(table(non_us))
names(n) <- c("COUNTRY", "FREQ")
which then gives me:
> dput(n)
structure(list(COUNTRY = structure(1:68, .Label = c("AE", "AR",
"AT", "AU", "BB", "BD", "BE", "BH", "BM", "BN", "BO", "BR", "BS",
"CA", "CH", "CM", "CN", "CO", "CR", "CY", "DE", "DK", "DO", "EC",
"ES", "FI", "FR", "GB", "GR", "GU", "HK", "ID", "IE", "IL", "IN",
"IO", "IT", "JM", "JP", "KH", "KR", "KY", "LU", "LV", "MO", "MX",
"MY", "NG", "NL", "NO", "NZ", "PA", "PE", "PG", "PH", "PR", "PT",
"RO", "RU", "SA", "SE", "SG", "TC", "TH", "TT", "TW", "TZ", "ZA"
), class = "factor"), FREQ = c(3L, 2L, 1L, 31L, 4L, 1L, 1L, 1L,
45L, 1L, 1L, 4L, 5L, 86L, 3L, 1L, 8L, 1L, 2L, 1L, 8L, 2L, 1L,
2L, 4L, 2L, 4L, 35L, 3L, 3L, 14L, 3L, 5L, 2L, 5L, 1L, 2L, 1L,
15L, 1L, 11L, 2L, 2L, 1L, 1L, 23L, 7L, 1L, 6L, 1L, 3L, 1L, 2L,
1L, 1L, 8L, 1L, 1L, 1L, 1L, 1L, 18L, 1L, 1L, 2L, 11L, 1L, 3L)), .Names =
c("COUNTRY",
"FREQ"), row.names = c(NA, -68L), class = "data.frame")

Then I do the following thinking that it would create the proper chart:
p <- ggplot(n, aes(x=COUNTRY, Y=FREQ)) + geom_bar() + coord_flip()
p
However, what I get is the x axis showing 'count' with a scale of 0.00 to
1.00. So then I try to change the limit of x to be from 0 to 100
p <- ggplot(n, aes(x=COUNTRY, Y=FREQ)) + geom_bar() + coord_flip()  +
xlim(0,100)
but I get an error: Error: Discrete value supplied to continuous scale.
I've tried googling that error and people talk about the data type not
being right, but for me str(n) shows
'data.frame': 68 obs. of  2 variables:
 $ COUNTRY: Factor w/ 68 levels "AE","AR","AT",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ FREQ   : int  3 2 1 31 4 1 1 1 45 1 ...

To confirm, when attempting to plot a count of occurrences by country in a
data frame with multiple possible rows per country, you have to aggregate
BEFORE passing it to ggplot?

I appreciate your time.


On Wed, Jan 15, 2014 at 12:58 PM, John Kane <jrkrideau@inbox.com> wrote:

> Thanks for the dput() data.frame.  It makes looking at the problem a lot
> easier.
>
> Basically you have a mucked-up data.frame. That is, what you see is not
> what you think you have.   You only have one variable in the data.frame and
> that is the country names.
>
> For some reason the numbers are being considered as row names not as a
> variable.  Do a str(filename) to see what is happening.  You do need to
> have an x and y value.
>
> Try something like this:
> library(ggplot2)
> dat1$val  <-  rownames(dat1) # create a new y value from the row names
> ggplot(dat1, aes(COUNTRY, val))+
>   geom_bar(stat = "identity", colour = "blue", fill = 'red', position =
> "dodge") +
>   coord_flip()
>
> It''s not  very pretty but it may give you a start. BTW I see that some
> countries (GB, CA, Au amongst others)  have multiple entries. Does this
> make sense or should you aggregate before graphing?
>
> John Kane
> Kingston ON Canada
>
> -----Original Message-----
> From: mrjefftoyou@gmail.com
> Sent: Wed, 15 Jan 2014 09:20:11 -0800
> To: jrkrideau@inbox.com
> Subject: Re: [R] Barplot not showing all labels
>
> Sorry guys, I'm running into an issue. I have a data frame. Here is the
> dput output having run:
>
> dput(head((non_us),25), file = "C:/Users/jeffjohn/Desktop/non_us_sam.csv",
> control = c("keepNA", "keepInteger","showAttributes"))
>
> structure(list(COUNTRY = structure(c(4L, 25L, 35L, 12L, 4L, 5L,
>
> 14L, 14L, 14L, 12L, 62L, 28L, 9L, 41L, 14L, 34L, 66L, 41L, 21L,
>
> 32L, 4L, 9L, 14L, 4L, 28L), .Label = c("AE", "AR", "AT", "AU",
>
> "BB", "BD", "BE", "BH", "BM", "BN", "BO", "BR", "BS", "CA", "CH",
>
> "CM", "CN", "CO", "CR", "CY", "DE", "DK", "DO", "EC", "ES", "FI",
>
> "FR", "GB", "GR", "GU", "HK", "ID", "IE", "IL", "IN", "IO", "IT",
>
> "JM", "JP", "KH", "KR", "KY", "LU", "LV", "MO", "MX", "MY", "NG",
>
> "NL", "NO", "NZ", "PA", "PE", "PG", "PH", "PR", "PT", "RO", "RU",
>
> "SA", "SE", "SG", "TC", "TH", "TT", "TW", "TZ", "ZA"), class = "factor")),
> .Names = "COUNTRY", row.names = c(329L,
>
> 1146L, 1474L, 1491L, 1585L, 1997L, 2190L, 2382L, 2442L, 2499L,
>
> 2703L, 3151L, 3278L, 3652L, 4730L, 5106L, 5214L, 5447L, 5710L,
>
> 5924L, 6185L, 6204L, 6258L, 6383L, 6811L), class = "data.frame")
>
> This data frame is called "non_us"
>
> I want to plot it so that it shows a chart of COUNTRY and the frequency of
> each (pretty simple I think). However, I don't know what to pass in for
> 'aes'.
>
> When I type names(non_us) it only shows "COUNTRY"
>
> Any suggestions for what to use for X and Y (assuming both are needed)?
>
> ggplot(non_us, aes(x=?, y=?))+ geom_bar(stat = "identity", colour = "red")
> + coord_flip()
>
> I appreciate your help VERY MUCH!
>
> Jeff
>
> World Vision
>
> On Tue, Jan 14, 2014 at 3:44 PM, Jeff Johnson <mrjefftoyou@gmail.com>
> wrote:
>
> Thanks John (and everyone else as well). John's example got it very close.
> I can tweak from here. Thanks!
>
> On Tue, Jan 14, 2014 at 1:22 PM, John Kane <jrkrideau@inbox.com> wrote:
>
>         I am not sure that I got the data correctly--it is much better to
> supply sample data using dput(). See ?dput for more information but I think
> something like this will work
>
>  dat1 / <-  structure(list(cty = structure(1:70, .Label = c("AE", "AN",
> "AR",
>
> "AT", "AU", "BB", "BD", "BE", "BH", "BM", "BN", "BO", "BR", "BS",
>  "CA", "CH", "CM", "CN", "CO", "CR", "CY", "DE", "DK", "DO", "EC",
>
> "ES", "FI", "FR", "GB", "GR", "GU", "HK", "ID", "IE", "IL", "IN",
>
> "IO", "IT", "JM", "JP", "KH", "KR", "KY", "LU", "LV", "MO", "MX",
>  "MY", "NG", "NL", "NO", "NZ", "PA", "PE", "PG", "PH", "PR", "PT",
>  "RO", "RU", "SA", "SE", "SG", "TC", "TH", "TT", "TW", "TZ", "US",
>
> "ZA"), class = "factor"), val = c(0, 3, 0, 2, 1, 31, 4, 1, 1,
>  1, 45, 1, 1, 4, 5, 86, 3, 1, 8, 1, 2, 1, 8, 2, 1, 2, 4, 2, 4,
>  35, 3, 3, 14, 3, 5, 2, 5, 1, 2, 1, 15, 1, 11, 2, 2, 1, 1, 23,
>  7, 1, 6, 1, 3, 1, 2, 1, 1, 8, 1, 1, 1, 1, 1, 18, 1, 1, 2, 11,
>  1, 0)), .Names = c("cty", "val"), row.names = c(NA, -70L), class =
> "data.frame")
>
>  library(ggplot2)
>  ggplot(dat1, aes(cty, val))+ geom_bar(stat = "identity", colour = "red")
> + coord_flip()
>
>  It will take some cleaning  up using theme() but I think it supplies the
> essentials that you want.
>
>  John Kane
>  Kingston ON Canada
>
>  > -----Original Message-----
>  > From: mrjefftoyou@gmail.com
>  > Sent: Mon, 13 Jan 2014 11:15:46 -0800
>  > To: r-help@r-project.org
>  > Subject: [R] Barplot not showing all labels
>  >
>  > I have a table that consists of the following country codes and
>  > frequencies:
>  >    AE AN AR AT AU BB BD BE BH BM BN BO BR BS CA CH CM CN CO CR CY DE DK
>  > DO
>  > EC ES
>  >  0  3  0  2  1 31  4  1  1  1 45  1  1  4  5 86  3  1  8  1  2  1  8  2
>  > 1
>  >  2  4
>  > FI FR GB GR GU HK ID IE IL IN IO IT JM JP KH KR KY LU LV MO MX MY NG NL
>  > NO
>  > NZ PA
>  >  2  4 35  3  3 14  3  5  2  5  1  2  1 15  1 11  2  2  1  1 23  7  1  6
>  > 1
>  >  3  1
>  > PE PG PH PR PT RO RU SA SE SG TC TH TT TW TZ US ZA
>  >  2  1  1  8  1  1  1  1  1 18  1  1  2 11  1  0  3
>  >
>  > I am executing:
>  > non_us <- table(subset(mydf, (COUNTRY %in% validcountries) & COUNTRY !=
>  > "US", select = COUNTRY))
>  >
>  > barplot(non_us,horiz=TRUE,xlab = "Count", ylab = "Country",main= "Count
>  > of
>  > Non-US Records by Country",col="red")
>  >
>  > It creates the attached image (I hope images come through on email).
>  > Notice
>  > that it is not displaying all of the country codes. It shows bars for
>  > each
>  > country, but only 6 are appearing.
>  >
>  > Does anyone have a suggestion? I'm open to using qplot, ggplot or
> ggplot2
>  > (and have tried that), but I want a bar (horizontal) chart not a column
>  > chart.
>  >
>  > Thanks in advance.
>  >
>  > --
>  > Jeff
>
> > ______________________________________________
>  > R-help@r-project.org mailing list
>  > https://stat.ethz.ch/mailman/listinfo/r-help [
> https://stat.ethz.ch/mailman/listinfo/r-help]
>  > PLEASE do read the posting guide
>  > http://www.R-project.org/posting-guide.html [
> http://www.R-project.org/posting-guide.html]
>  > and provide commented, minimal, self-contained, reproducible code.
>
> ____________________________________________________________
>  FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on
> your desktop!
>  Check it out at http://www.inbox.com/marineaquarium [
> http://www.inbox.com/marineaquarium]
>
> --
>
> Jeff
>
> --
>
> Jeff
>
> ____________________________________________________________
> FREE ONLINE PHOTOSHARING - Share your photos online with your friends and
> family!
> Visit http://www.inbox.com/photosharing to find out more!
>
>
>


-- 
Jeff

	[[alternative HTML version deleted]]


