1. 3D Interactive Plot

Here's a 3D interactive plot I like from the ebook "R Fundamentals & Graphics". I've just started learning BLENDER and want to see if I can transfer these 3D images to BLENDER and save it as a .COLLADA file. Has anyone ever done that? Apple has a software called iBook Author which can accommodate interactive 3D images in COLLADA format in ebooks. Their promo video is really cool!

Code:
``````library(rgl)
x <- seq(-3,3, length=50)
y <- x
f <- function (x,y) {x*exp (-x^2-y^2)}
z <- outer (x,y,f)
plot3d (x,y,z, box=F, axes=F, xlab="",ylab="",zlab="")
surface3d (x,y,z,col=heat.colors(30))``````

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

JesperHP (08-12-2014), trinker (04-24-2014)

3. Re: [R Graphics] Beautiful graphics thread

I guess this belongs here. Its a shiny App. And I love it.

http://spark.rstudio.com/uafsnap/ak_...precipitation/

4. The Following User Says Thank You to bugman For This Useful Post:

JesperHP (08-12-2014)

5. Re: [R Graphics] Beautiful graphics thread

http://gjabel.wordpress.com/2014/03/...ow-plots-in-r/

probably more beautiful than useful.

7. Re: [R Graphics] Beautiful graphics thread

Just for fun. I saw this image (from: http://www.pewinternet.org/2015/01/2...ety-00-01/)and wanted to replicate it as an exercise.

Here's my result:

I provided the data beolw. See if you can do better. I used ggplot2 + Inkskape for some touchups. I left the code.

Code:
``````dat <- data.frame(
freq = c(37, 88, 47, 89, 28, 68, 65, 98, 68, 86, 50, 87, 59, 82, 45, 65, 52, 32, 59, 47, 68, 78, 39, 31, 64, 68)
)

dat[["sector"]] <- rep(c("U.S. adults", "AAAS scientist"), nrow(dat)/2)

field <- c("Biomedical sciences", "Climate, energy, space sciences")
dat[["field"]] <- factor(rep(field, c(10, 16)), levels=field)

items <-  c(
"Safe to eat genetically\nmodified foods",
"Favor the use of animas\nin research",
"Safe to eat foods grown\nwith pesticides",
"Humans have evolved over\ntime",
"Childhood vaccines such\nas MMR should be required  ",
"Climate change is mostly\ndue to human activity",
"Growing world population\nwill be a major problem",
"Favor building more\nnuclear power plants",
"Favor more offshore\ndrilling",
"Astronaughts essential for\nfuture of U.S. space program",
"Favor increased use of\nbioengineered fuel",
"Favor increased use of\nfracking",
"Space station has been\na good investment for U.S."
)

dat[["Item"]] <- factor(rep(items, each=2), levels=rev(items))

library(dplyr)

diffs <- dat %>%
group_by(Item, field) %>%
summarise(
diff = abs(diff(freq)),
mid = mean(freq),
xmin = min(freq),
xmax=max(freq)
)

ext <- rep("", nrow(diffs))
ext[c(5, 13)] <- "point gap"

ext2 <- rep("", nrow(diffs))
ext2[c(5, 13)] <- "%"

#amt <- 2
amt <- 1.5

library(ggplot2)

ggplot(dat, aes(y = Item, x=freq)) +
geom_segment(data=diffs, aes(x=xmin, xend=xmax, y=Item, yend=Item), color="royalblue2", size=5.5) +
geom_point(color = "navy", size=5.5) +
geom_point(shape=21, color = "navy", size=4.8, aes(fill=sector)) +
facet_grid(field~., space="free", scales="free") +
scale_fill_manual(values = c("white", "darkblue"), guide=FALSE) +
theme_bw() +
coord_cartesian(xlim = c(24, 102)) +
ylab(NULL) + xlab(NULL) +
geom_text(data = diffs, color = "white",
aes(label = paste(diff, ext), x=mid, y=Item),
size=3, vjust = .4, hjust=.2) +
geom_text(data = diffs, color = "grey60", aes(label = paste0(xmin, ext2), x=xmin -amt, y=Item),
size=3, vjust = .4, hjust=1) +
geom_text(data = diffs, color = "grey60", aes(label = paste0(xmax, ext2), x=xmax + amt, y=Item),
size=3, vjust = .4, hjust=0)   +
theme(
axis.text.y = element_text(hjust=0),
axis.text.x = element_blank(),
axis.ticks = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_blank(),
panel.border = element_blank(),
strip.background = element_rect(color=NA, fill="grey75"),
strip.text.y = element_text(size=12, face="bold", hjust=.05),
panel.margin = unit(1, "lines")
) +
geom_hline(color="grey60", linetype="dotted", size=.7,  aes(yintercept=.5))``````

8. The Following 4 Users Say Thank You to trinker For This Useful Post:

bugman (02-03-2015), jbwettergreen (12-14-2016), TheEcologist (02-04-2015), vinux (02-04-2015)

9. Re: [R Graphics] Beautiful graphics thread

I see at least 2 spelling typos in the items

10. Re: [R Graphics] Beautiful graphics thread

TE gave a 'Thanks' to a ggplot graph.

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

trinker (02-04-2015)

12. Re: [R Graphics] Beautiful graphics thread

Originally Posted by vinux
TE gave a 'Thanks' to a ggplot graph.
The thanks went to trinker. Still technically all the work IS being done in base - trinker is just evoking ggplot to "talk" to base for him.

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

trinker (02-04-2015)

14. Re: [R Graphics] Beautiful graphics thread

Is his stance softening

15. Re: [R Graphics] Beautiful graphics thread

Good work. However, I am not a fan of the figure - it is kind of confusing or not immediately readable. It needs the full scale 0-100 listed some where relative to the values.

Perhaps you can also see what happens if you color code the magnitude of the gaps based on say yellow to red continuum, instead of all being blue.

16. The Following User Says Thank You to hlsmith For This Useful Post:

trinker (02-04-2015)

17. Re: [R Graphics] Beautiful graphics thread

I can appreciate your thoughts on Pew's figure. It could probably use some upgrades. I'm not sure I agree with the points you raise. These is my thinking and justification. Feel free to disagree. I love chatting around these issues and debating them as I have mostly qualitative people in my department and these aren't the issues they discuss so the debate is usually in my head

Originally Posted by hlsmith
It needs the full scale 0-100 listed some where relative to the values.
The scale is implicit with the inclusion of percentages. Whenever we can get rid of an axis scale and put it with the geom our eyes are doing less back and forth. I like that the scale info is on the geom as it gives precise values like a table would but it's in grey so it's not primary in where our eyes go. We have to focus attention to see these. The percentages are only done once in each multiple to avoid extra ink. I liked that. Related, I liked the direct labels of Scientist and Us adults. This again reduces back and forth looking up of labels.

Originally Posted by hlsmith
Perhaps you can also see what happens if you color code the magnitude of the gaps based on say yellow to red continuum, instead of all being blue.
I can see your point on the gradient but this information is already coded in the length between the points. Adding a gradient would probably aid in comparison but the best preattentive attribute we have for comparing continuous values is length. Color gradient is typically a poorer choice, particularly with smaller geoms like points. I think because the segments have different zero values comparison is not as easy and a gradient may improve this. It also runs the risk of distracting from other trends shown that are already using color (i.e., the way the scientists and people flop on 3 items; this is shown with color on the point and a gradient may distract from this).

I liked it because it minimized the data ink ratio without compromising information presented. This blog post on data ink I thought was pretty powerful: http://darkhorseanalytics.com/blog/d...-better-naked/

18. Re: [R Graphics] Beautiful graphics thread

I can tell you like your graph. I had not notice the flip-flopping of the group orders and the respective differences. That is confusing as well, I may not have even noticed that it happened in the same categories. Perhaps you should use a different color when the groups flip-flop. You did a good job copying the figure, now you need to improve it. The original could not have been perfect or without any room for improvement - now is the time to maximize readability.

Yeah, I have no one at my work to bounce ideas off of, I can appreciate your situation!

19. The Following User Says Thank You to hlsmith For This Useful Post:

trinker (02-04-2015)

20. Re: [R Graphics] Beautiful graphics thread

Originally Posted by hlsmith
now you need to improve it
Agreed. This sounds like a challenge. Anyone that wants to submit an idea I included the data and as a csv for non R users as well.

I was thinking a bumpchart may show the trends better.

dat.xlsx

Code:
``````dat <- structure(list(freq = c(37, 88, 47, 89, 28, 68, 65, 98, 68, 86,
50, 87, 59, 82, 45, 65, 52, 32, 59, 47, 68, 78, 39, 31, 64, 68
"AAAS scientist", "U.S. adults", "AAAS scientist"), field = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Biomedical sciences",
"Climate, energy, space sciences"), class = "factor"), Item = structure(c(13L,
13L, 12L, 12L, 11L, 11L, 10L, 10L, 9L, 9L, 8L, 8L, 7L, 7L, 6L,
6L, 5L, 5L, 4L, 4L, 3L, 3L, 2L, 2L, 1L, 1L), .Label = c("Space station has been\na good investment for U.S.",
"Favor increased use of\nfracking", "Favor increased use of\nbioengineered fuel",
"Astronauts essential for\nfuture of U.S. space program", "Favor more offshore\ndrilling",
"Favor building more\nnuclear power plants", "Growing world population\nwill be a major problem",
"Climate change is mostly\ndue to human activity", "Childhood vaccines such\nas MMR should be required  ",
"Humans have evolved over\ntime", "Safe to eat foods grown\nwith pesticides",
"Favor the use of animas\nin research", "Safe to eat genetically\nmodified foods"
), class = "factor")), .Names = c("freq", "sector", "field",
"Item"), row.names = c(NA, -26L), class = "data.frame")``````

21. Re: [R Graphics] Beautiful graphics thread

I decided a bar plot may be best here. I toned down colors all together and focused on the differences between scientists and the US people. TO me that's the narrative. As such I ordered the Items by larges difference. I didn't go with direct percent labels this time to draw attention to the geoms.

All in ggplot2 + grid/gridExtra:

Code:
``````library(dplyr)

sect_dat <- split(dat, dat[["sector"]])

diffs <- dat %>%
group_by(Item, field) %>%
summarise(
diff = -diff(freq),
mid = mean(freq),
xmin = min(freq),
xmax=max(freq)
)

dat[["Item"]] <- factor(as.character(dat[["Item"]]),
levels = as.character(unlist(diffs[order(diffs[["diff"]]), "Item"])))

gr1 <- ggplot(data = dat) +
geom_bar(data=subset(sect_dat[[1]], field == "Climate, energy, space sciences"),
aes(x=Item, weight=freq), fill="grey90") +
geom_bar(data=subset(sect_dat[[2]], field == "Climate, energy, space sciences"),
aes(x=Item, weight=freq), width=.5, fill="grey70") +
coord_flip(ylim = c(0, 100)) +
scale_y_continuous(breaks=c(0, 25, 50, 75, 100), labels=function(x) paste0(x, "%")) +
theme_minimal() + xlab(NULL) + ylab(NULL) +
theme(
axis.ticks = element_blank(),
panel.grid.minor = element_blank(),
panel.grid.major.y = element_blank(),
axis.text.y = element_text(hjust=0),
title = element_text(hjust=0, color="grey40"),
axis.text = element_text(color = "grey50"),
plot.margin=unit(c(-2,6,3,1),"mm")
) + ggtitle("Climate, energy, space sciences")

gr2 <- ggplot(data = dat) +
geom_bar(data=subset(sect_dat[[1]], field != "Climate, energy, space sciences"),
aes(x=Item, weight=freq), fill="grey90") +
geom_bar(data=subset(sect_dat[[2]], field != "Climate, energy, space sciences"),
aes(x=Item, weight=freq), width=.5, fill="grey70") +
coord_flip(ylim = c(0, 100)) +
scale_y_continuous(breaks=c(0, 25, 50, 75, 100), labels=function(x) paste0(x, "%")) +
theme_minimal() + xlab(NULL) + ylab(NULL) +
theme(
axis.ticks = element_blank(),
panel.grid.minor = element_blank(),
panel.grid.major.y = element_blank(),
axis.text.y = element_text(hjust=0),
title = element_text(hjust=0, color="grey40"),
axis.text.x = element_blank(),
axis.text = element_text(color = "grey50"),
plot.margin=unit(c(0,6,0,1),"mm")
) + ggtitle("Biomedical sciences") +
annotate("text",  x = 5, y = 2, hjust = 0, size=3.75,
label = "U.S. adults", color = "grey95")+
annotate("text",  x = 5, y = 85, hjust = 1, size=3.75,
label = "AAAS scientist", color = "grey50")

library(gridExtra)
library(plotflow)

gA <- ggplotGrob(gr1)
gB <- ggplotGrob(gr2)
maxWidth <- unit.pmax(gA\$widths[2:5], gB\$widths[2:5])
gA\$widths[2:5] <- as.list(maxWidth)
gB\$widths[2:5] <- as.list(maxWidth)
grid.arrange(gB, gA, heights=c(.38, .62))``````

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

TheEcologist (04-23-2015)

23. Re: [R Graphics] Beautiful graphics thread

What is a geom?

Page 5 of 9 First 1 2 3 4 5 6 7 8 9 Last

 Tweet