楼主: Lisrelchen
3762 23

Instant Heat Maps in R How-to [推广有奖]

  • 0关注
  • 62粉丝

VIP

已卖:4194份资源

院士

67%

还不是VIP/贵宾

-

TA的文库  其他...

Bayesian NewOccidental

Spatial Data Analysis

东西方数据挖掘

威望
0
论坛币
50288 个
通用积分
83.6306
学术水平
253 点
热心指数
300 点
信用等级
208 点
经验
41518 点
帖子
3256
精华
14
在线时间
766 小时
注册时间
2006-5-4
最后登录
2022-11-6

楼主
Lisrelchen 发表于 2015-3-1 12:48:08 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
About This Book
  • Learn something new in an Instant! A short, fast, focused guide delivering immediate results
  • Create heat maps in R using different file formats
  • Learn how to make choropleth maps and contour plots
  • Generate your own customized heat maps and add interactivity for displaying on the web


Who This Book Is For

Heat Maps in R How-to is the book for you if you want to make use of this free and open source software to get the most out of your data analysis. You need to have at least some experience in using R and know how to run basic scripts from the command line. However, knowledge of other statistical scripting languages such as Octave, S-Plus, or MATLAB will suffice to follow along with the recipes. You need not be from a statistics background.

本帖隐藏的内容

Instant Heat Maps in R How-to.pdf (2.17 MB, 需要: 20 个论坛币)






二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Instant Heat maps STAN Ant displaying different something software source

已有 2 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
statax + 100 + 20 + 3 奖励积极上传好的资料
crystal8832 + 48 + 3 + 3 + 3 奖励积极上传好的资料

总评分: 经验 + 100  论坛币 + 68  学术水平 + 3  热心指数 + 6  信用等级 + 3   查看全部评分

本帖被以下文库推荐

沙发
Lisrelchen(未真实交易用户) 发表于 2015-3-1 12:50:01
  1. ### loading packages
  2. if (!require("gplots")) {
  3. install.packages("gplots", dependencies = TRUE)
  4. library(RColorBrewer)
  5. }
  6. if (!require("RColorBrewer")) {
  7. install.packages("RColorBrewer", dependencies = TRUE)
  8. library(RColorBrewer)
  9. }

  10. ### reading in data
  11. gene_data <- read.csv("arabidopsis_genes.csv")
  12. row_names <- gene_data[,1]
  13. gene_data <- data.matrix(gene_data[,2:ncol(gene_data)])
  14. rownames(gene_data) <- row_names
  15. cat("\n\narabidopsis_genes.csv\n")
  16. print(gene_data)

  17. ### setting heatmap.2() default parameters
  18. heat2 <- function(...) heatmap.2(gene_data,
  19.         tracecol = "black",
  20.         dendrogram = "column",
  21.         Rowv = NA,
  22.         trace = "none",
  23.         margins = c(8,10),
  24.         density.info = "density", ...)

  25. pdf("custom_heatmaps.pdf")

  26. ### 1) customizing colors
  27. # 1.1) in-built color palettes
  28. heat2(col = terrain.colors(n = 1000),
  29.         main = "1.1) Terrain Colors")

  30. # 1.2) RColorBrewer palettes
  31. heat2(col = brewer.pal(n = 9, "YlOrRd"),
  32.         main = "1.2) Brewer Palette")

  33. # 1.3) creating own color palettes
  34. my_colors <- c(y1 = "#F7F7D0",
  35.         y2 = "#FCFC3A",
  36.         y3 = "#D4D40D",
  37.         b1 = "#40EDEA",
  38.         b2 = "#18B3F0",
  39.         b3 = "#186BF0",
  40.         r1 = "#FA8E8E",
  41.         r2 = "#F26666",
  42.         r1 = "#C70404")
  43. heat2(col = my_colors,
  44.         main = "1.3) Own Color Palette")
  45. my_palette <- colorRampPalette(c("blue", "yellow", "red"))(n = 1000)
  46. heat2(col = my_palette, main = "1.3) ColorRampPalette")

  47. # 1.4) gray scale
  48. heat2(col = gray(level = (0:100)/100),
  49.         main ="1.4) Gray Scale")

  50. ### 2) adding cell notes
  51. fold_change <- 2^gene_data
  52. rounded_fold_changes  <- round(fold_change, 2)
  53. heat2(cellnote = rounded_fold_changes,
  54.         notecex = 0.5,
  55.         notecol = "black",
  56.         col = my_palette,
  57.         main = "2) Cell Notes")
  58. cat("\n\narabidopsis_genes.csv Fold changes\n")

  59. ### 3) adding column side colors
  60. heat2(ColSideColors = c("red", "gray", "red", rep("green", 13)),
  61.         main = "3) ColSideColors")

  62. dev.off()
  63. cat("\n\nHeat maps saved as ", getwd(),
  64.         "/custom_heatmaps.pdf", sep = "")
复制代码

藤椅
Lisrelchen(未真实交易用户) 发表于 2015-3-1 12:50:41
  1. ### loading packages

  2. if (!require("ggplot2")) {
  3. install.packages("ggplot2", dependencies = TRUE)
  4. library(ggplot2)
  5. }
  6. if (!require("maps")) {
  7. install.packages("maps", dependencies = TRUE)
  8. library(maps)
  9. }
  10. if (!require("mapdata")) {
  11. install.packages("mapdata", dependencies = TRUE)
  12. library(mapdata)
  13. }
  14. if (!require("fields")) {
  15. install.packages("fields", dependencies = TRUE)
  16. library(fields)
  17. }

  18. pdf("chloropleth_maps.pdf", height = 7,width = 10)

  19. ### 1) average temperature USA

  20. # 1.1) reading in and processing data
  21. usa_map <- map_data(map = "state")

  22. usa_temp <- read.csv("usa_temp.csv", comment.char = "#")

  23. usa_data <- merge(usa_temp, usa_map,
  24. by.x ="state", by.y = "region") # case sensitive

  25. usa_sorted <- usa_data[order(usa_data["order"]),]

  26. # 1.2) plotting USA chloropleth maps
  27. usa_map1 <- ggplot(data = usa_sorted) +
  28.         geom_polygon(aes(x = long, y = lat,
  29. group = group, fill = fahrenheit)) +
  30.         ggtitle("USA Map 1")
  31. print(usa_map1)

  32. usa_map2 <- usa_map1 + coord_map("polyconic") +
  33.         ggtitle("USA Map 2 - polyconic")
  34. print(usa_map2)

  35. usa_map3 <- usa_map2 +
  36.         geom_path(aes(x = long, y = lat, group = group),
  37. color = "black") +
  38.         ggtitle("USA Map 3 - black contours")
  39. print(usa_map3)

  40. usa_map4 <- usa_map3 +
  41.         scale_fill_gradient(low = "yellow", high = "red") +
  42.         ggtitle("USA Map 4 - gradient 1")
  43. print(usa_map4)

  44. usa_map5 <- usa_map3 +
  45. scale_fill_gradient2(low = "steelblue", mid = "yellow",
  46.         high = "red",  midpoint = colMeans(usa_sorted["fahrenheit"])) +
  47.         ggtitle("USA Map 5 - gradient 2")
  48. print(usa_map5)


  49. ### 2) South American population count

  50. # 2.1) reading in and processing data
  51. south_am_map <- map_data("worldHires",
  52. region = c("Argentina", "Bolivia", "Brazil",
  53.         "Chile", "Colombia", "Ecuador", "Falkland Islands",
  54. "French Guiana", "Guyana", "Paraguay", "Peru",
  55. "Suriname", "Uruguay", "Venezuela"))

  56. south_am_pop <- read.csv("south_america_pop.csv",
  57. comment.char = "#")

  58. south_am_data <- merge(south_am_pop, south_am_map,  
  59.         by.x = "country", by.y = "region")

  60. south_am_sorted <- south_am_data[order(
  61. south_am_data["order"]),]

  62. # 2.2) creating chloropleth maps
  63. south_am_map1 <- ggplot(data = south_am_sorted) +
  64.         geom_polygon(aes(x = long, y = lat,
  65. group = group, fill = population)) +
  66.         geom_path(aes(x = long, y = lat, group = group),
  67. color = "black") +
  68.         coord_map("polyconic") +
  69. scale_fill_gradient(low = "lightyellow",
  70.         high = "red", guide = "legend")
  71. print(south_am_map1)

  72. south_am_map2 = south_am_map1 +
  73.         theme(panel.background = element_blank(),
  74.         axis.text = element_blank(),
  75.         axis.title = element_blank(),
  76.         axis.ticks = element_blank())
  77. print(south_am_map2)

  78. dev.off()
  79. cat("Heat maps saved as ", getwd(),
  80. "/chloropleth_maps.pdf", sep = "")

  81. ### 3) Volcano contour plot

  82. pdf("contour_plot.pdf", height = 7,width = 10)

  83. data(volcano)
  84. image.plot(volcano)
  85. contour(volcano, add = TRUE)

  86. dev.off()

  87. cat("Heat maps and contour plot saved as ", getwd(),
  88. "/chloropleth_maps.pdf and", getwd(), "/contour_plot.pdf" , sep = "")
复制代码

板凳
Lisrelchen(未真实交易用户) 发表于 2015-3-1 12:51:23
  1. if (!require("gplots")) {
  2. install.packages("gplots", dependencies = TRUE)
  3. library(gplots)
  4. }
  5. if (!require("RColorBrewer")) {
  6. install.packages("RColorBrewer", dependencies = TRUE)
  7. library(gplots)
  8. }

  9. ### converting data
  10. data(co2)
  11. rowcolNames <- list(as.character(1959:1997), month.abb)
  12. co2_data <- matrix(co2,
  13.         ncol = 12,
  14.         byrow = TRUE,
  15.         dimnames = rowcolNames)

  16. heat2 <- function(...)
  17.         heatmap.2(co2_data,trace = "none",
  18.         density.info = "none",
  19.         dendrogram = "none",
  20.         Colv = FALSE,
  21.         Rowv = FALSE,
  22.         col = colorRampPalette(c("blue", "yellow", "red"))(n = 100),
  23.         margin = c(5,8),
  24.         lhei = c(0.25,1.25),
  25.          ...)


  26. png("1_PNG_default.png")

  27. heat2(main = "PNG default")
  28. dev.off()

  29. png("2_PNG_highres.png",
  30.         width = 5*300,
  31.         height = 5*300,
  32.         res = 300,
  33.         pointsize = 8)
  34. heat2(main = "PNG High Resolution")
  35. dev.off()

  36. jpeg("3_JPEG_highres.png",
  37.         width = 5*300,
  38.         height = 5*300,
  39.         res = 300,
  40.         pointsize = 8)
  41. heat2(main = "JPEG default")
  42. dev.off()

  43. bmp("4_BMP_default.bmp",
  44. width = 5*300,
  45.         height = 5*300,
  46.         res = 300,
  47.         pointsize = 8)
  48. heat2(main = "BMP default")
  49. dev.off()

  50. pdf("5_PDF_default.pdf",
  51.         width = 5,
  52.         height = 5,
  53.         pointsize = 8)
  54. heat2(main = "PDF default")
  55. dev.off()

  56. svg("6_SVG_default.svg",
  57.         width = 5,
  58.         height = 5,
  59.         pointsize = 8)
  60. heat2(main = "SVG default")
  61. dev.off()

  62. postscript("7_PostScript_default.ps",
  63.         width = 5,
  64.         height = 5,
  65.         pointsize = 8)
  66. heat2(main = "PostScript default")
  67. dev.off()

  68. png("8_PNG_transp.png",
  69.         width = 5*300,
  70.         height = 5*300,
  71.         res = 300,
  72.         pointsize = 8,
  73.         bg = "transparent")
  74. heat2(main = "PNG Transparent Background")
  75. dev.off()

  76. pdf("9_PDF_mono.pdf",
  77.         family = "Courier",
  78.         paper = "USr")
  79. heat2(main = "PDF Monospace Font")
  80. dev.off()

  81. cat("Heat maps saved in ", getwd(),
  82.         sep = "")
复制代码

报纸
eric5488(未真实交易用户) 发表于 2015-3-1 23:59:18
謝謝分享

地板
soccy(未真实交易用户) 发表于 2015-3-2 00:12:54
新书吧

7
soccy(未真实交易用户) 发表于 2015-3-2 00:15:04
2013年的,不新了

8
fhc2010(未真实交易用户) 发表于 2015-3-2 01:06:18
look, thanks

9
bocm(未真实交易用户) 发表于 2015-3-2 08:23:34
thanks for sharing

10
lhf8059(真实交易用户) 发表于 2015-3-2 08:48:40
看看!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-31 07:13