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

Thread: [R Graphics] Beautiful graphics thread

  1. #1
    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 608 Times in 341 Posts

    [R Graphics] Beautiful graphics thread




    Hi Everyone,

    I thought I might start a thread which showcases the graphics abilities of R. I'll start it off with one I just made.

    This thread was also inspired by bg and trinker claiming that this could never be done in R.
    Of course it can you just won't be able 1) to showcase it in R but it works nice with any non IE browser or 2) do it in ggplot. This is SVG, and its enormously powerful!

    (fyi Combining R with SVG and XML can put you in the position to make amazing presentations <- that is sozi, its good, but you can also use jezzyink)

    To make graphs like the above and the below, you need to get down and dirty with all the functions at the base of ggplot and beyond (head over to the "darkside").

    So I'll start off with this example, I was inspired to improve on it after I saw someone's attempt to do it in ggplot.

    Hopefully this hits off and we can share some amazing graphics and code with each other. My next goal will be do show how you can do this in R.

    So here is my attempt at making a more realistic "Earth at Night in R, using only base graphics" ;



    For some reason it looks much better in R, so just copy paste the following;

    Code: 
    # Earth at night in R
    # took about 30 minutes to code
    
    require(maps)
    data(world.cities)
    #subset minor and major cities
    minmajdat=world.cities[world.cities$pop>10000,]
    
    #subset major cities
    majdat=world.cities[world.cities$pop>100000,]
    
    #subset huge cities
    hdat=world.cities[world.cities$pop>1000000,]
    
    ranker=rank(world.cities$pop)
    
    par(bg=rgb(0,0,0.025),mex=0.5,mar=c(0,0,0,0))
    
    map("world",col=rgb(0,0,0.55,
    alpha=0.05),interior=F,fill=T)
    
    #plot huge cities
    points(hdat$lat[ranker]~hdat$long[ranker],col=rgb(0.25,0.25,0,alpha=0.05)
    ,pch='.',cex=(hdat$pop)^c(1/100))
    
    # illumate the night
    
    	for(i in 1:5){
    points(jitter(world.cities$lat[ranker],1)~jitter(world.cities$long[ranker],1),
    col=rgb(230/255,232/255, 250/255,alpha=0.0075),pch='.',cex=(world.cities$pop)^c(1/100))
    	}
    
    #create light haze arround minor & major cities
    	for(i in 1:5){
    icol=rgb(0.7,0.7,0.7,alpha=0.02)
    points(jitter(minmajdat$lat[ranker],10)~
    jitter(minmajdat$long[ranker],10),
    col=icol,pch='.',cex=(minmajdat$pop)^c(1/100))
    	}
    
    #create yellow light haze arround major cities
    	for(i in 1:6){
    icol=rgb(1,1,0,alpha=0.02)
    points(jitter(majdat$lat[ranker],10)~
    jitter(majdat$long[ranker],10),
    col=icol,pch='.',cex=(majdat$pop)^c(1/100))
    	}
    
    #create bright light haze arround huge cities
    	for(i in 1:6){
    icol=rgb(1,1,1,alpha=0.02)
    points(jitter(hdat$lat[ranker],10)~
    jitter(hdat$long[ranker],10),
    col=icol,pch='.',cex=(hdat$pop)^c(1/100))
    	}
    Looking forward to seeing your contributions.

    TE
    The true ideals of great philosophies always seem to get lost somewhere along the road..

  2. The Following 10 Users Say Thank You to TheEcologist For This Useful Post:

    bugman (10-17-2012), Dason (10-17-2012), IevaB (10-14-2015), Jake (10-17-2012), Lazar (10-23-2012), SiBorg (10-23-2012), soxi (04-10-2013), Sttepanka (11-15-2017), trinker (10-23-2012), vinux (10-17-2012)

  3. #2
    Devorador de queso
    Points: 97,539, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Posting AwardCommunity AwardDiscussion EnderFrequent PosterActivity Award
    Dason's Avatar
    Location
    Tampa, FL
    Posts
    12,987
    Thanks
    309
    Thanked 2,640 Times in 2,255 Posts

    Re: [R Graphics] Beautiful graphics thread

    I just have one thing to add

    THE ENTIRE WORLD HAS GONE DARK! THE SUN IS DEAD! WE SURELY WILL NOT SURVIVE.
    I don't have emotions and sometimes that makes me very sad.

  4. #3
    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

    Here is one on TS chat data. There is nothing new in graphical side. Here is the chat summary (I have removed the chat contents for confidential reason) Dataset. It is an intraday analysis of chat data. I have taken IST as the reference. I thought of adding one more scale. But I don't wanted to confuse with day light saving system. Some of the US folks they just need to change am to pm and pm to am.




    Here you can find the code.

    Code: 
    ## Reading the chat data set
    ts <- read.csv(insert_url_for_dropbox_csv_here) # Send a message if you need to know what the file is.
    ts$dt <- strptime(ts$Date, "%m/%d %H:%M") 
    ts$dttime <- as.POSIXlt(ts$dt, "IST") 
    
    ## grouping the users not the top ten best chatters
    nTop10bUsers <- ts$User.Name %in% c("bugman", "CowboyBear",  "Dragan",
                                        "hlsmith",  "Lazar", "ledzep", "Link", "noetsi",
                                        "quark", "SiBorg", "SmoothJohn" )
    ts$Chatter <- ts$User.Name
    ts$Chatter[nTop10bUsers] <- "Others"
    
    
    chat.colour <- c("bryangoodrich"="limegreen", "Dason"="red", "GretaGarbo"="green", "Jake"="brown", "jimmy brooks"="gold", "Others"="grey", "spunky"="cyan", "TheEcologist"="darkred", "trinker"="indianred3", "victorxstc"="yellow", "vinux"="blue")
    
    
    
    nf <- layout(matrix(c(2, 5, 1, 3, 4, 0), 3, 2, byrow=TRUE), c(9, 3), c(3, 9, 2), TRUE)
    
    par(mar=c(1, 4, 1, 1))
    cdplot( as.factor(ts$Chatter) ~ ts$dttime$hour, col=chat.colour, xlab="Time", ylab="Users")
    ## axis(side=1,at=1:24, labels=c("Midnight", paste(1:11), "Noon",paste(1:11)),srt=90)
    
    par(mar=c(0, 4, 0, 0))
    chat.t <- barplot( tapply(ts$Chatter, ts$dttime$hour, length), col=gray(c(seq(0.1, 1, length=12),seq(1, 0.1, length=12))))
    text(y=100, x=chat.t, label=c("Midnight", paste(1:11, "am"), "Noon",paste(1:11, "pm")), srt=90)
    
    par(mar=c(0, 0, 0, 0))
    chat.s <- table(ts$Chatter)
    chat.sbar <- barplot(chat.s, col=chat.colour, yaxt="n", horiz=TRUE)
    text(y=chat.sbar, x=chat.s*.5, label=names(chat.s))
    
    par(mar=c(4, 4, 1, 1))
    x <- seq(-pi, pi, len=24)
    y=0
    r <- outer(x, y, "+")
    image(z = z <- 1-sin(r/2)^2,x,y, col=gray((0:32)/32),xlab="Time (Intraday)",xaxs="i",xaxt="n",yaxt="n",ylab="")
    
    par(mar=rep(0, 4), cex=0.5)
    plot.new()
    plot.window(c(0,1), 0:1)
    par(family="sans", lheight=4.5)
    text(.35, .75, "TalkStats",font=4,cex=1.5)
    text(.35, .55, "Intraday Analysis",font=2) 
    text(.35, .35, "Top 10 best Chatters",cex=.85)
    I tried to automate the color from the chat. I will try this next time. Now some findings. You can identify the sleeping/working time. What I can observe is all humans sleep at least 2-3 hours. Rest is left to you.

    EDIT: Changed Chron functions
    Attached Thumbnails Attached Thumbnails Click image for larger version

Name:	Rplot.jpeg‎
Views:	165
Size:	169.2 KB
ID:	2777   Click image for larger version

Name:	Rplot.jpeg‎
Views:	93
Size:	166.0 KB
ID:	2778  
    In the long run, we're all dead.

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

    GretaGarbo (10-23-2012), Jake (10-23-2012), JMarcelino (10-23-2015), TheEcologist (10-23-2012), trinker (10-23-2012)

  6. #4
    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 608 Times in 341 Posts

    Re: [R Graphics] Beautiful graphics thread

    Can we now conclude that Dason doesn't sleep? (and who also doesn't sleep children?)

    @vinux, does your code need a require(chron)? - Oh and great graphic!
    The true ideals of great philosophies always seem to get lost somewhere along the road..

  7. The Following User Says Thank You to TheEcologist For This Useful Post:

    hlsmith (10-23-2012)

  8. #5
    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 TheEcologist View Post
    Can we now conclude that Dason doesn't sleep? (and who also doesn't sleep children?)

    @vinux, does your code need a require(chron)?
    Unfortunately yes. I thought of removing that.

    My stupidity. I could have used ts$dttime$hour.


    EDIT: I have removed chron function now. It is purely a base R example.
    In the long run, we're all dead.

  9. #6
    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 608 Times in 341 Posts

    Re: [R Graphics] Beautiful graphics thread

    Oke, as discussed in the chatbox.. I slight improvement to the (already incredible) design using a visually more stimulating palette (I strongly recommend using palette's in all your colour graphs - it is more appealing to the human brain - below find my homemade mineral palette)

    Code: 
    #Mineral palette - HEX CODES FROM:http://rapid-tools.net/online-color-picker/
    mineral.colors=colorRampPalette(c("#d67646","#943d2c","#474243","#e6bc78",
    "#decfba")) 
    
    #APPLIED TO VINUX's great graphic
    
    ## Reading the chat data set
    ts <- read.csv(insert_url_for_dropbox_csv_here) # Send a message if you need to know what the file is.
    ts$dt <- strptime(ts$Date, "%m/%d %H:%M") 
    ts$dttime <- as.POSIXlt(ts$dt, "IST") 
    
    ## grouping the users not the top ten best chatters
    nTop10bUsers <- ts$User.Name %in% c("bugman", "CowboyBear",  "Dragan",
                                        "hlsmith",  "Lazar", "ledzep", "Link", "noetsi",
                                        "quark", "SiBorg", "SmoothJohn" )
    ts$Chatter <- ts$User.Name
    ts$Chatter[nTop10bUsers] <- "Others"
    
    
    chat.colour=mineral.colors(length(unique(ts$Chatter)))
    names(chat.colour)=unique(ts$Chatter)
    
    
    
    nf <- layout(matrix(c(2, 5, 1, 3, 4, 0), 3, 2, byrow=TRUE), c(9, 3), c(3, 9, 2), TRUE)
    
    par(mar=c(1, 4, 1, 1))
    cdplot( as.factor(ts$Chatter) ~ ts$dttime$hour, col=chat.colour, xlab="Time", ylab="Users")
    ## axis(side=1,at=1:24, labels=c("Midnight", paste(1:11), "Noon",paste(1:11)),srt=90)
    
    par(mar=c(0, 4, 0, 0))
    chat.t <- barplot( tapply(ts$Chatter, ts$dttime$hour, length), col=gray(c(seq(0.1, 1, length=12),seq(1, 0.1, length=12))))
    text(y=100, x=chat.t, label=c("Midnight", paste(1:11, "am"), "Noon",paste(1:11, "pm")), srt=90)
    
    par(mar=c(0, 0, 0, 0))
    chat.s <- table(ts$Chatter)
    chat.sbar <- barplot(chat.s, col=chat.colour, yaxt="n", horiz=TRUE)
    text(y=chat.sbar, x=chat.s*.5, label=names(chat.s))
    
    par(mar=c(4, 4, 1, 1))
    x <- seq(-pi, pi, len=24)
    y=0
    r <- outer(x, y, "+")
    image(z = z <- 1-sin(r/2)^2,x,y, col=gray((0:32)/32),xlab="Time (Intraday)",xaxs="i",xaxt="n",yaxt="n",ylab="")
    
    par(mar=rep(0, 4), cex=0.5)
    plot.new()
    plot.window(c(0,1), 0:1)
    par(family="sans", lheight=4.5)
    text(.35, .75, "TalkStats",font=4,cex=1.5)
    text(.35, .55, "Intraday Analysis",font=2) 
    text(.35, .35, "Top 10 best Chatters",cex=.85)

    It now looks like this:


    What do you think Vinux?
    The true ideals of great philosophies always seem to get lost somewhere along the road..

  10. The Following 2 Users Say Thank You to TheEcologist For This Useful Post:

    trinker (10-23-2012), vinux (10-23-2012)

  11. #7
    Omega Contributor
    Points: 39,120, Level: 100
    Level completed: 0%, Points required for next Level: 0
    hlsmith's Avatar
    Location
    Not Ames, IA
    Posts
    7,082
    Thanks
    402
    Thanked 1,194 Times in 1,155 Posts

    Re: [R Graphics] Beautiful graphics thread

    It would be interesting to incorporate or consider the inter-relationship between chatters. Obviously some individuals co-mingle more and the chat is more lively at certain times. Is the time based on the international date line and medians over a week?

  12. #8
    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 608 Times in 341 Posts

    Re: [R Graphics] Beautiful graphics thread

    Oke, because it is autumn. I thought I would add my autumn R palette

    Code: 
    
    # Color Palette
    
    #Autumn palette
    indiansummer.colors=colorRampPalette(c("gold","#FFB11F", "#FC4D04","#755E02", "#191E01","#B0050A","red")) 
    
    #APPLIED TO VINUX's great graphic
    
    ## Reading the chat data set
    ts <- read.csv(insert_url_for_dropbox_csv_here) # Send a message if you need to know what the file is.
    ts$dt <- strptime(ts$Date, "%m/%d %H:%M") 
    ts$dttime <- as.POSIXlt(ts$dt, "IST") 
    
    ## grouping the users not the top ten best chatters
    nTop10bUsers <- ts$User.Name %in% c("bugman", "CowboyBear",  "Dragan",
                                        "hlsmith",  "Lazar", "ledzep", "Link", "noetsi",
                                        "quark", "SiBorg", "SmoothJohn" )
    ts$Chatter <- ts$User.Name
    ts$Chatter[nTop10bUsers] <- "Others"
    
    
    chat.colour=indiansummer.colors(length(unique(ts$Chatter)))
    names(chat.colour)=unique(ts$Chatter)
    
    
    
    nf <- layout(matrix(c(2, 5, 1, 3, 4, 0), 3, 2, byrow=TRUE), c(9, 3), c(3, 9, 2), TRUE)
    
    par(mar=c(1, 4, 1, 1))
    cdplot( as.factor(ts$Chatter) ~ ts$dttime$hour, col=chat.colour, xlab="Time", ylab="Users")
    ## axis(side=1,at=1:24, labels=c("Midnight", paste(1:11), "Noon",paste(1:11)),srt=90)
    
    par(mar=c(0, 4, 0, 0))
    chat.t <- barplot( tapply(ts$Chatter, ts$dttime$hour, length), col=gray(c(seq(0.1, 1, length=12),seq(1, 0.1, length=12))))
    text(y=100, x=chat.t, label=c("Midnight", paste(1:11, "am"), "Noon",paste(1:11, "pm")), srt=90)
    
    par(mar=c(0, 0, 0, 0))
    chat.s <- table(ts$Chatter)
    chat.sbar <- barplot(chat.s, col=chat.colour, yaxt="n", horiz=TRUE)
    text(y=chat.sbar, x=chat.s*.5, label=names(chat.s))
    
    par(mar=c(4, 4, 1, 1))
    x <- seq(-pi, pi, len=24)
    y=0
    r <- outer(x, y, "+")
    image(z = z <- 1-sin(r/2)^2,x,y, col=gray((0:32)/32),xlab="Time (Intraday)",xaxs="i",xaxt="n",yaxt="n",ylab="")
    
    par(mar=rep(0, 4), cex=0.5)
    plot.new()
    plot.window(c(0,1), 0:1)
    par(family="sans", lheight=4.5)
    text(.35, .75, "TalkStats",font=4,cex=1.5)
    text(.35, .55, "Intraday Analysis",font=2) 
    text(.35, .35, "Top 10 best Chatters",cex=.85)
    So now with Indian summer colours -->



    Again, thanks for the wonderful graphic vinux!
    The true ideals of great philosophies always seem to get lost somewhere along the road..

  13. The Following User Says Thank You to TheEcologist For This Useful Post:

    trinker (10-23-2012)

  14. #9
    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 hlsmith View Post
    It would be interesting to incorporate or consider the inter-relationship between chatters. Obviously some individuals co-mingle more and the chat is more lively at certain times. Is the time based on the international date line and medians over a week?
    Here is first level of inter-relationship between chatters. You can ignore the diagonal part.


    Code: 
    ## Reading the chat data set
    ts <- read.csv(insert_url_for_dropbox_csv_here) # Send a message if you need to know what the file is.
    
    ## Not in the top ten best chatters
    nTop10bUsers <- ts$User.Name %in% c("bugman", "CowboyBear",  "Dragan",
                                        "hlsmith",  "Lazar", "ledzep", "Link", "noetsi",
                                        "quark", "SiBorg", "SmoothJohn" )
    
    ts$Chatter <- ts$User.Name
    ts$Chatter[nTop10bUsers] <- "Others"
    
    ## chat.table <- table(ts$Chatter[1:nrow(ts)-1], ts$Chatter[2:nrow(ts)])
    chat.table <- table(ts$Chatter[1:(nrow(ts)-1)], ts$Chatter[2:nrow(ts)])
    ## This may not make sense
    assocplot(chat.table)
    chat.matrix <- as.matrix(chat.table)
    diag(chat.matrix) <- 0
    par(mar=c(6, 6, 1, 1), las=2)
    assocplot(chat.matrix, space=0.1, main="Chat (t) vs Chat (t+1)")
    Black shows the positive association. You can see the clusters. Victor-greta, trinker-Dason, VInux-TE, jake-Dason. Dason is positively associated with most of the users.

    One could also try mosaicplot.

    EDIT: Incorporated Dason's correction
    In the long run, we're all dead.

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

    TheEcologist (10-23-2012), trinker (10-23-2012)

  16. #10
    ggplot2orBust
    Points: 72,900, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,424
    Thanks
    1,815
    Thanked 931 Times in 812 Posts

    Re: [R Graphics] Beautiful graphics thread

    To some extend this reveals where we live. People in the states have similar shapes where as people on the other side of the world have the opposite shapes. Lovin' this thread.
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  17. #11
    ggplot2orBust
    Points: 72,900, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,424
    Thanks
    1,815
    Thanked 931 Times in 812 Posts

    Re: [R Graphics] Beautiful graphics thread

    gotta tear this association plot apart. I'm wondering if the association is based on proximity or mention of someone's name (ie @vinux) but haven't run the code.
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  18. #12
    Omega Contributor
    Points: 39,120, Level: 100
    Level completed: 0%, Points required for next Level: 0
    hlsmith's Avatar
    Location
    Not Ames, IA
    Posts
    7,082
    Thanks
    402
    Thanked 1,194 Times in 1,155 Posts

    Re: [R Graphics] Beautiful graphics thread

    You also have to remember that victorxstc sometimes thinks outloud and will post dozens of posts without really communicating with anyone in particular! Perhaps someone in the social sciences or psych can better make the appropriate consideration for this anomaly

  19. #13
    Devorador de queso
    Points: 97,539, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Posting AwardCommunity AwardDiscussion EnderFrequent PosterActivity Award
    Dason's Avatar
    Location
    Tampa, FL
    Posts
    12,987
    Thanks
    309
    Thanked 2,640 Times in 2,255 Posts

    Re: [R Graphics] Beautiful graphics thread

    It doesn't change anything since using an index of 0 essentially is ignored but...
    Code: 
    #in this line:
    chat.table <- table(ts$Chatter[1:nrow(ts)-1], ts$Chatter[2:nrow(ts)])
    # we have
    ts$Chatter[1:nrow(ts)-1]
    # but it should be
    ts$Chatter[1:(nrow(ts)-1)]
    # but this is even better
    ts$Chatter[seq(nrow(ts)-1)]
    I don't have emotions and sometimes that makes me very sad.

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

    vinux (10-23-2012)

  21. #14
    Points: 5,259, Level: 46
    Level completed: 55%, Points required for next Level: 91
    SiBorg's Avatar
    Posts
    255
    Thanks
    71
    Thanked 25 Times in 22 Posts

    Re: [R Graphics] Beautiful graphics thread

    Can we sticky this thread?

    Also, from the chatbox statistics, I think we can say that Greta and Victor are very likely to be starting up a relationship (p<0.0001).

  22. The Following User Says Thank You to SiBorg For This Useful Post:

    trinker (10-23-2012)

  23. #15
    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 608 Times in 341 Posts

    Re: [R Graphics] Beautiful graphics thread


    Quote Originally Posted by SiBorg View Post
    Can we sticky this thread?
    Done (on condition everyone else agrees).

    Quote Originally Posted by SiBorg View Post
    Also, from the chatbox statistics, I think we can say that Greta and Victor are very likely to be starting up a relationship (p<0.0001).
    lol
    The true ideals of great philosophies always seem to get lost somewhere along the road..

+ Reply to Thread
Page 1 of 9 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