I obtained compositional maps of my rock sample (thin-section) using micro-XRF (Bruker)
The image below is the obtained data. It is the compositional (intensity) map of one element.
I try to change the color using r.
Library
library(dplyr)
library(tibble)
library(tidyr)
library(ggplot2)
library(tidyverse)
library(fields)
library(RColorBrewer)
read data (raw data of micro-XRF mapping, text file)
test1 <- read.table("test1.txt", sep =";")
test2 <- read.table("test2.txt", sep =";") read data
head(test1)## V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15
## 1 38 76 164 260 635 1649 2686 3130 2970 2615 2578 3221 3296 3358 3316
## 2 0 285 512 469 586 1367 2384 2932 2603 2273 2429 2932 3178 3313 3115
## 3 210 611 1251 1493 1046 656 1363 2265 2678 2655 2487 2542 2858 3041 2979
## 4 0 2218 2504 1966 1042 1409 2379 2880 2992 2941 2514 2204 2311 2153 1478
## 5 1445 2348 2814 2610 1738 1287 2131 2880 3174 3166 2962 1957 1340 1136 877
## 6 0 2694 2270 1401 993 1800 2842 3187 3169 2984 1978 667 304 248 169
## V16 V17 V18 V19 V20 V21 V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33
## 1 2905 2249 1246 877 571 349 248 191 187 163 136 113 58 33 18 13 11 10
## 2 2513 1490 969 828 472 248 235 241 160 164 147 141 105 59 19 14 14 12
## 3 2393 1304 794 944 974 492 268 246 186 147 132 179 210 172 88 15 12 6
## 4 757 501 803 1024 591 282 227 156 88 74 111 184 187 111 35 15 10 9
## 5 472 294 318 673 745 419 231 194 96 47 40 83 106 134 98 49 8 11
## 6 131 146 308 426 357 207 167 81 28 21 42 70 100 138 82 16 12 16
## V34 V35 V36 V37 V38 V39 V40 V41 V42 V43 V44 V45 V46 V47 V48 V49 V50 V51 V52
## 1 11 11 13 18 11 12 7 15 20 17 10 14 7 14 13 11 14 5 11
## 2 16 8 9 8 14 10 12 9 5 14 14 11 8 12 10 13 12 8 6
## 3 12 10 15 15 11 12 6 7 9 9 23 22 14 16 10 13 10 6 11
## 4 10 10 10 9 13 11 17 12 8 18 18 21 17 17 14 15 7 11 6
## 5 9 11 17 18 11 11 5 11 8 10 15 16 8 15 10 9 7 17 9
## 6 10 16 18 9 14 7 13 8 9 4 9 15 8 14 6 4 11 11 9
......Each cell shows the intensity of the element of each data point (pixel).
visualizing data
x <- as.matrix(test1)
image(x)I want a scale bar.
Plot is tilted 90 degrees from the original map....
data transformation
x <- as.matrix(test1)
(y <- t(x[nrow(x):1,ncol(x):1])[ncol(x):1,])## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
## V1 0 967 0 450 0 1002 0 2802 0 464 0 1446 0 3298
## V2 3343 2598 2906 1695 2522 1814 2330 2155 1258 511 134 962 1873 3172
## V3 3226 3146 2233 2632 1883 2805 1853 1764 806 422 146 492 1096 2945
## V4 2784 2686 944 1460 1325 1988 1218 1144 369 358 214 312 643 2096
## V5 1393 1460 429 930 874 1394 579 500 282 233 271 316 326 1031
## V6 650 438 252 517 332 608 312 285 278 231 258 250 260 355
## V7 452 348 267 250 549 329 1007 289 292 249 270 280 234 229
## V8 292 308 425 365 1688 1492 2605 751 1027 284 300 285 273 230
## V9 248 286 1066 1156 2905 2941 3305 2148 2702 669 644 253 242 231
## V10 269 376 1132 2423 3120 3394 3444 3295 3309 2096 1898 353 420 171
## V11 255 326 438 2160 2916 3466 3377 3432 3332 3114 3150 1544 1564 157
......
## V117 6 14
## V118 6 5
## V119 12 14
## [ reached getOption("max.print") -- omitted 281 rows ]
visualizing data 2-1
image.plot(y)
Now I want to change the color palette
visualizing data 2-2 (changing color)
my_col = brewer.pal(3, "RdYlBu")
pal <- colorRampPalette(my_col)
image.plot(y, col = pal(100))visualizing data 2-3 (changing color)
my_col = brewer.pal(7, "RdYlBu")
pal <- colorRampPalette(my_col)
image.plot(y, col = pal(100))Compared to the original image, now it is easier to see the differences in intensity.
visualizing data 2-4 (changing color)
Using an original color palette
my_col = colorRampPalette(c("hotpink", "grey99", "dodgerblue"))
image.plot(y,col = my_col(100))visualizing data 2-5 (changing color)
my_col = colorRampPalette(c("hotpink", "grey99", "dodgerblue"))
image.plot(y,col = my_col(5))visualizing data 2-6 (changing color)
my_col = colorRampPalette(c("royalblue2", "grey99", "tomato2"))
image.plot(y,col = my_col(100))saving data (map)
jpeg("image.jpg")
image.plot(y,col = my_col(5))
dev.off()Another element (test2)
x <- as.matrix(test2)
(y2 <- t(x[nrow(x):1,ncol(x):1])[ncol(x):1,])## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
## V1 0 775 0 894 0 480 0 228 0 881 0 740 0 66
## V2 24 318 113 424 159 329 211 395 649 931 1019 845 580 103
## V3 32 47 268 153 318 161 340 373 628 903 880 893 610 169
## V4 125 144 563 411 508 376 467 506 693 705 676 729 603 356
## V5 431 421 587 557 526 488 605 620 659 654 614 656 595 513
## V6 592 633 640 600 627 602 653 572 663 657 620 653 625 601
## V7 599 660 654 622 658 657 511 714 652 645 636 614 591 642
## V8 676 610 5visualizing data (test2 data)
my_col = brewer.pal(3, "RdYlBu")
pal <- colorRampPalette(my_col)
image.plot(y2, col = pal(100))



.png)
.png)






0 Comments