+ Reply to Thread
Page 3 of 9 FirstFirst 1 2 3 4 5 6 7 8 9 LastLast
Results 31 to 45 of 121

Thread: [R Graphics] Beautiful graphics thread

  1. #31
    Probably A Mammal
    Points: 31,087, Level: 100
    Level completed: 0%, Points required for next Level: 0
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    2,564
    Thanks
    398
    Thanked 618 Times in 551 Posts

    Re: [R Graphics] Beautiful graphics thread




    Tr, Vinux's plot was an intraday graphic. I'm saying take a composite over multiple days so that an hour slice represents some function of the aggregate at that hour on all days. Then any people that have clustering should align closely and all be in one graph. Your multi-day plot appears to have different time scales on the x-axis. The only way to see how people tend to cluster over days would be if the plots were stacked on top of each other with the same scale. Then you can essentially take a slice down the plots to see how people cluster at that time. Trying to evaluate something like that for a month or a year would basically be incomprehensible. Instead, I was proposing an aggregation of the multi-day information into one plot. Each person's outcome is a function of the distribution of the phenomena over multiple days.

  2. #32
    Dark Knight
    Points: 6,762, Level: 54
    Level completed: 6%, Points required for next Level: 188
    vinux's Avatar
    Posts
    2,011
    Thanks
    52
    Thanked 241 Times in 205 Posts

    Re: [R Graphics] Beautiful graphics thread

    Plot1: Clustering based on the time. Clustering based 24 variables ( 0-1, 1-2, ...).
    Caution: spy diagrams ahead.
    Plot2: I have seen the season package in the latest R journal. We could achieve the same by stars.
    Plot3. Further drill down of plot2.
    Name:  chatgraph.jpeg
Views: 1340
Size:  106.8 KB

    Code: 
    ts <- read.csv(insert_url_for_dropbox_csv_here, stringsAsFactors=FALSE)
    
    ts$dt <- strptime(ts$Date, "%m/%d %H:%M")
    ts$dttime <- as.POSIXlt(ts$dt, "IST")
    
    ts$hourgroup <- cut(ts$dttime$hour, breaks=c(-1, 6, 12, 18, 24), labels=c("0-6", "6-12", "12-18", "18-24"))
    ts$wdays <- factor( weekdays(ts$dttime, abbreviate=TRUE), levels=c("Sun", "Mon", "Tue", "Wed", "Thu","Fri","Sat"))
    chat.wtable <- table(ts$wdays)
    
    ## PLOT 1
    par(mfrow=c(1, 2))
    plot(hclust(dist(as.data.frame.matrix(table( ts$User.Name, ts$dttime$hour))), "ave"), main="Cluster Based on Time", xlab="Users", frame.plot=T,  yaxt="n")
    ## PLOT 2
    library(season)
    plotCircular(chat.wtable, labels=names(chat.wtable), lines=T, pieces.col="brown", main="Weekly data")
    
    ## PLOT 3
    stars(as.data.frame.matrix(table(ts$wdays, ts$hourgroup)), key.loc= c(6, 4.5), key.labels="Clock",  draw.segments=TRUE, col.segments=gray(c(0.1, .9, .8, .2)), nrow=4, ncol=3, main="Chats by Time and Weekday", frame.plot=TRUE)
    The clustering brings timezone matches. Even I change the methods the clusters look similar. In the second graph. It is showing the seasonality. It seems chatbox is very active in the last three working days.


    I am thinking of exploring grid graphics. It would be fun adding "SVG + Javascript" to make it interactive.

    If anyone can suggest some interesting data, we could all analyze on that.
    In the long run, we're all dead.

  3. The Following 2 Users Say Thank You to vinux For This Useful Post:

    TheEcologist (06-07-2013), trinker (10-25-2012)

  4. #33
    ggplot2orBust
    Points: 71,220, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,417
    Thanks
    1,811
    Thanked 928 Times in 809 Posts

    Re: [R Graphics] Beautiful graphics thread

    @BG still not sure if I know what you mean. Is this what you're thinking? Plus should the scaling be done by person or just overall? I did it by person.

    Code: 
    library(ggplot2); library(talkstats); library(plyr); library(reshape2)
    dat <- ts_chatbox()
    dat$hour <- sapply(strsplit(as.character(dat$time), ":"), 
        function(x) x[c(T, F, F)])
    
    dat3 <- data.frame(with(dat, table(person, date, hour)))
    x3 <- melt(dat3)
    x3 <- ddply(x3, .(person), transform, rescale = rescale(value))
    
    ggplot(x3, aes(hour, date, group=person)) + geom_tile(aes(fill = rescale),
        colour = "white") + scale_fill_gradient(low = "gold",
        high = "darkviolet") + theme_grey() + labs(x = "",
        y = "") + scale_x_discrete(expand = c(0, 0)) +
        scale_y_discrete(expand = c(0, 0)) + theme(legend.position = "none",
        axis.ticks = element_blank(), axis.text.x = element_text(angle = -90, 
            hjust = 0, colour = "grey50")) + facet_wrap(~person, ncol=3)
    For a pdf of this plot -click here-

    Or maybe by date instead?

    Code: 
    ggplot(x3, aes(hour, person, group=person)) + geom_tile(aes(fill = rescale),
        colour = "white") + scale_fill_gradient(low = "gold",
        high = "darkviolet") + theme_grey() + labs(x = "",
        y = "") + scale_x_discrete(expand = c(0, 0)) +
        scale_y_discrete(expand = c(0, 0)) + theme(legend.position = "none",
        axis.ticks = element_blank(), axis.text.x = element_text(angle = -90, 
            hjust = 0, colour = "grey50")) + facet_wrap(~date, ncol=3)
    -click here-
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  5. #34
    Probably A Mammal
    Points: 31,087, Level: 100
    Level completed: 0%, Points required for next Level: 0
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    2,564
    Thanks
    398
    Thanked 618 Times in 551 Posts

    Re: [R Graphics] Beautiful graphics thread

    Vinux, that star graph is nice! It clearly shows that people talk the most Wednesday through Friday and aren't that active on the weekends, which I know, but I would always think people would be more active! Mainly because that's when I'm more active since I work all day and can't use TS lol

    Trinker, that heat map looks good. The scales are all the same now so when I look at a certain point on one graph then I know it's the same time point on the other graph, but a nice transformation of the data now would be to look at a time point (say Dason at 8 PM) across all the days. Maybe just take the median value. Do that for all time points. Then we'd have a composite single graph representing what hour people are the busiest. With Vinux's star graph, this composite can also be done by day, so we can see which hour people are most active on a given day given all the days data we have.

  6. #35
    ggplot2orBust
    Points: 71,220, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,417
    Thanks
    1,811
    Thanked 928 Times in 809 Posts

    Re: [R Graphics] Beautiful graphics thread

    @BG I tried median and it wasn't informative except for three people so I used mean instead.

    Code: 
    ggplot(x3, aes(hour, person, group=person)) + geom_tile(aes(fill = rescale),
        colour = "white") + scale_fill_gradient(low = "white",
        high = "darkblue") + theme_grey() + labs(x = "",
        y = "") + scale_x_discrete(expand = c(0, 0)) +
        scale_y_discrete(expand = c(0, 0)) + theme(legend.position = "none",
        axis.ticks = element_blank(), axis.text.x = element_text(angle = -90, 
        vjust = .1, colour = "grey50"))
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  7. The Following 2 Users Say Thank You to trinker For This Useful Post:

    bryangoodrich (10-25-2012), vinux (10-25-2012)

  8. #36
    ggplot2orBust
    Points: 71,220, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,417
    Thanks
    1,811
    Thanked 928 Times in 809 Posts

    Re: [R Graphics] Beautiful graphics thread

    @Vinux who's zorro?
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  9. #37
    TS Contributor
    Points: 22,374, Level: 93
    Level completed: 3%, Points required for next Level: 976
    spunky's Avatar
    Location
    vancouver, canada
    Posts
    2,135
    Thanks
    166
    Thanked 537 Times in 431 Posts

    Re: [R Graphics] Beautiful graphics thread

    lol @ trinker & Dason being close together... the eternal battle of the bots VS the raptors will continue forever...

    ps- so... why am i associated with jimmy brooks?
    for all your psychometric needs! https://psychometroscar.wordpress.com/about/

  10. #38
    ggplot2orBust
    Points: 71,220, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,417
    Thanks
    1,811
    Thanked 928 Times in 809 Posts

    Re: [R Graphics] Beautiful graphics thread

    If you're talking about Vinux's it's because you both speak during the same time intervals. However we don't know if it's on the same day. Also Jimmy Brooks has almost no words spoken (see below):

    This gives some basic word statistics (ignore sentence because I didn't break it up by sentence; that's more our turns of talk or chat inputs).
    Code: 
    library(qdap); library(talkstats)
    dat <- ts_chatbox()
    with(dat, word_stats(dialogue, person))
    Here's a link to a txt data frame of the stats as it's pretty long: LINK
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  11. #39
    Dark Knight
    Points: 6,762, Level: 54
    Level completed: 6%, Points required for next Level: 188
    vinux's Avatar
    Posts
    2,011
    Thanks
    52
    Thanked 241 Times in 205 Posts

    Re: [R Graphics] Beautiful graphics thread

    Quote Originally Posted by trinker View Post
    If you're talking about Vinux's it's because you both speak during the same time intervals. However we don't know if it's on the same day. Also Jimmy Brooks has almost no words spoken (see below):

    This gives some basic word statistics (ignore sentence because I didn't break it up by sentence; that's more our turns of talk or chat inputs).
    Code: 
    library(qdap); library(talkstats)
    dat <- ts_chatbox()
    with(dat, word_stats(dialogue, person))
    Here's a link to a txt data frame of the stats as it's pretty long: LINK
    Trinker, I used the old data for my last graphs, where jimmy was one other top ten. For clustering my idea was to identify the timezone (Just because we have the reference so it can easily comparable). I mean the variable I have created in that way.
    In the long run, we're all dead.

  12. The Following User Says Thank You to vinux For This Useful Post:

    trinker (10-25-2012)

  13. #40
    ggplot2orBust
    Points: 71,220, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,417
    Thanks
    1,811
    Thanked 928 Times in 809 Posts

    Re: [R Graphics] Beautiful graphics thread

    Oh I didn't realize it had changed that much.
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  14. #41
    Probably A Mammal
    Points: 31,087, Level: 100
    Level completed: 0%, Points required for next Level: 0
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    2,564
    Thanks
    398
    Thanked 618 Times in 551 Posts

    Re: [R Graphics] Beautiful graphics thread

    I like the graph trinker! I wonder what other aggregation we can do, maybe something that accounts for timezone (since every hour is locally different), and include a scale on the right to show what the continuous variable represents (graphs need to be completely informative, at least in the final analysis).

  15. #42
    R purist
    Points: 35,103, Level: 100
    Level completed: 0%, Points required for next Level: 0
    TheEcologist's Avatar
    Location
    United States
    Posts
    1,921
    Thanks
    303
    Thanked 607 Times in 341 Posts

    Re: [R Graphics] Beautiful graphics thread

    I decided to showcase the use of images in R graphics.

    Lets take a look at the forum's from a spammer perspective. Generally speaking its a dangerous place, with ravenous moderators around each corner waiting to devour their posts and ban them for all eternity. Thus lets see how the TS mods compare in evil (from a spammers perspective) to famous cinema villains.

    Using data from the net, on villain body counts and comparing these to the mod ban statistics we can get a mle estimate of how the mods compare to famous villains. This finally give us an opportunity to scientifically prove who is a raptor and who is a (Skynet) bot. [I would want to compare mods to super heroes but there is no way to rank super heroes objectively that I can think of]. In the analysis I assume that ban stats are a Poisson distributed random variable.

    So here are the results;



    And here is the script (make sure to download the images zip file and set your working directory);

    Code: 
    
    #have you set your image working directory yet?
    
    setwd("/home/marco/images")
    
    killcount=sort(structure(c(9L, 6L, 89L, 33L, 8L, 34L), .Dim = 6L, .Dimnames = structure(list(
        dat = c("bugman", "CowboyBear", "Dason", "Dragan", "quark", 
        "TheEcologist")), .Names = "dat"), class = "table"))
    
    # Movie Villains kill stats taken from the net
    villains=structure(list(Kills = c(6, 10, 18, 22, 32, 35, 42, 57, 64), 
        name = structure(c(8L, 1L, 5L, 2L, 3L, 4L, 6L, 9L, 7L), .Label = c("Alien", 
        "Jason", "Chucky", "DarthVader", "Dracula", "FreddyKrueger", 
        "Predator", "Raptors", "Terminator"), class = "factor")), .Names = c("Kills", 
    "name"), row.names = c(4L, 3L, 5L, 7L, 8L, 6L, 9L, 2L, 1L), class = "data.frame")
    
    
    #blood palette
    tibetanmonk.colors=colorRampPalette(c("#FC580C","#FC6B0A","#F8872E","#FFA927","#FDCA49")) 
    
    # Blood splash background
    require(biOps)
    bloodbackground=readJpeg("bloodspatter.jpeg")
    
    # Add labels and text
    text(1,1,"A")
    
    #layout matrix made earlier in spreadsheet program
    layoutmat=
    structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 77L, 1L, 17L, 26L, 35L, 
    44L, 53L, 62L, 8L, 1L, 18L, 27L, 36L, 45L, 54L, 63L, 9L, 1L, 
    19L, 28L, 37L, 46L, 55L, 64L, 10L, 1L, 20L, 29L, 38L, 47L, 56L, 
    65L, 11L, 1L, 21L, 30L, 39L, 48L, 57L, 66L, 12L, 1L, 22L, 31L, 
    40L, 49L, 58L, 67L, 13L, 1L, 23L, 32L, 41L, 50L, 59L, 68L, 14L, 
    1L, 24L, 33L, 42L, 51L, 60L, 69L, 15L, 1L, 25L, 34L, 43L, 52L, 
    61L, 70L, 16L, 1L, 71L, 72L, 73L, 74L, 75L, 76L, 1L), .Dim = c(8L, 
    11L), .Dimnames = list(NULL, c("V1", "V2", "V3", "V4", "V5", 
    "V6", "V7", "V8", "V9", "V10", "V11")))
    
    
    # Load avatars
    
    Avatars=vector("list",5)
    
    Avatars[[6]]=readJpeg("ClassyDogCropSmallPng.jpg")
    Avatars[[4]]=readJpeg("avat2.jpg")
    Avatars[[2]]=readJpeg("darkhorse.jpg")
    Avatars[[3]]=readJpeg("index.jpeg")
    Avatars[[5]]=readJpeg("Viva-La-Evolucion-T-Shirt-(8147).jpg")
    Avatars[[1]]=readJpeg("Mr.jpg")
    
    par(mar=c(0,0,0,0),xaxt="n",yaxt="n")
    layout(layoutmat)
    
    plot(bloodbackground)
    
    # add text
    lims=dim(bloodbackground)[1:2]
    
    #Title
    text(lims[2]/2,lims[1]-40,expression(bold("How Moderators Compare to Movie Villains")),cex=3,col="blue")
    
    # MLE
    text(lims[2]-40,lims[1]-60,expression(bold("MLE")),cex=2,col="blue")
    
    #mod
    text(0+40,lims[1]-60.5,expression(bold("MOD")),cex=2,col="blue")
    
    
    for(i in 1:6){
    plot(Avatars[[i]])
    }
    
    
    for(i in 1:9){
    vilpic=readJpeg(paste(villains[,2][i],".jpg",sep=""))
    plot(vilpic)
    }
    
    
    for(i in 1:6){
    	
    	for (j in 1:dim(villains)[1]){
    	barplot(dpois(villains[j,1],killcount[i]),
    	col=tibetanmonk.colors(dim(villains)[1])[j],
    	ylim=c(0,max(dpois(villains[,1],killcount[i]))))
    			}
    }
    
    
    for(i in 1:6){
    l=dpois(villains[,1],killcount[i])
    mle=which(l==max(l))
    vilpic=readJpeg(paste(villains[,2]
    [mle],".jpg",sep=""))
    plot(vilpic)
    }
    
    
    plot(-100,ylim=c(0,1),xlim=c(0,1))
    As we can see there are certainly Raptors on the forum, Dragan is as deadly as Chucky, Dason is likely the Predator but cant be significantly distinguished from the T101 (a bot). Quark, like his DS9 Ferengi bar-tender counterpart, is likely an Alien (but still most likely a Raptor)... bugman will incubate his spawn in your abdomen... and funny enough I'm Darth Vader.

    So come on over to the Darkside and join me in the power of (wrapper free) R graphics

    Note; the mod stats may not reflect actual clean-up contributions of the moderators, as we have an automatic spammer "remove all posts and ban" button.. which does not get recorded in the stats. Some mods may therefore be more deadly than the image suggests
    Attached Files
    The true ideals of great philosophies always seem to get lost somewhere along the road..

  16. The Following 3 Users Say Thank You to TheEcologist For This Useful Post:

    bugman (10-27-2012), trinker (10-27-2012), vinux (10-28-2012)

  17. #43
    ggplot2orBust
    Points: 71,220, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,417
    Thanks
    1,811
    Thanked 928 Times in 809 Posts

    Re: [R Graphics] Beautiful graphics thread

    Does this mean quark is a raptor?
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  18. #44
    R purist
    Points: 35,103, Level: 100
    Level completed: 0%, Points required for next Level: 0
    TheEcologist's Avatar
    Location
    United States
    Posts
    1,921
    Thanks
    303
    Thanked 607 Times in 341 Posts

    Re: [R Graphics] Beautiful graphics thread

    Quote Originally Posted by trinker View Post
    Does this mean quark is a raptor?
    Indeed a Raptor. But it really all boils down towards whether you are a Frequentest or a Bayesian. You see the mode of the likelihood distribution is a Raptor, but Bayesians would be more interested in the mean which is an Alien , I w

    Also, as I am Darth Vader, I would like to urge bugman to finish that death star in his avatar. I want it fully operational!
    The true ideals of great philosophies always seem to get lost somewhere along the road..

  19. #45
    Dark Knight
    Points: 6,762, Level: 54
    Level completed: 6%, Points required for next Level: 188
    vinux's Avatar
    Posts
    2,011
    Thanks
    52
    Thanked 241 Times in 205 Posts

    Re: [R Graphics] Beautiful graphics thread


    Happy birthday to Velociraptor. I made this one using raptor's favourite package

    Code: 
    rapt = read.csv("http://dl.dropbox.com/u/32095775/raptor.csv")
    library(ggplot2)
      ggplot(data=rapt) + geom_polygon(aes(x=V1, y=V2, group=group), colour=I("gray") )+ theme_bw() + scale_x_continuous(limits = c(0, 400)) +   scale_y_continuous(limits = c(0, 250)) + 
      geom_text(aes(100,230, label="Happy Birthday Raptor"))+
      theme(axis.line=element_blank(), axis.text.x=element_blank(),  axis.text.y=element_blank(),axis.ticks=element_blank(), axis.title.x=element_blank(),    axis.title.y=element_blank(),legend.position="none", panel.background=element_blank(),panel.border=element_blank(), panel.grid.major=element_blank(), panel.grid.minor=element_blank(), plot.background=element_blank())
    In the long run, we're all dead.

  20. The Following User Says Thank You to vinux For This Useful Post:

    trinker (11-15-2012)

+ Reply to Thread
Page 3 of 9 FirstFirst 1 2 3 4 5 6 7 8 9 LastLast

           




Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats