我正在嘗試在 384 孔板實驗中創建與發光值相對應的點網格。我將盤子繪制為 .png 檔案并覆寫網格,這樣每個點都應該位于盤子的一個井中。提供的示例代碼和資料。
可以用ggplot2做到這一點嗎?
我正在使用以下代碼(提供的示例資料):
library(ggplot2)
library(png)
library(RCurl)
library(grid)
example.gg <- read.csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vRcX5aMZGCp9Bs3BRZSg8k4o-kbSjOO5z3LsRxgIv4qJHz1fG-Argruje32OuZ2Tt2qPaNGksGr4Jia/pub?output=csv",
row.names = 1)
example.gg$Row <- factor(example.gg$Row, levels = rev(sort(unique(example.gg$Row))))
png.img <- readPNG(getURLContent("https://i.imgur.com/QeSO7d3.png"))
img.rg <- rasterGrob(png.img, interpolate=TRUE)
gp <- ggplot(example.gg,
aes(x = Col, y = Row, col = Lum))
annotation_custom(img.rg, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)
geom_point(shape = 15)
theme_void()
gp
這是制作的影像:

回答
感
uj5u.com熱心網友回復:
xmin通過使用/ xmax& ymin/手動調整影像的位置,使用ymax固定行和列的間距coord_fixed(clip = "off)并擴展plot.marginin,theme我能夠得到看起來可行的東西。
library(ggplot2)
library(png)
library(RCurl)
library(grid)
example.gg <- read.csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vRcX5aMZGCp9Bs3BRZSg8k4o-kbSjOO5z3LsRxgIv4qJHz1fG-Argruje32OuZ2Tt2qPaNGksGr4Jia/pub?output=csv",
row.names = 1)
example.gg$Row <- factor(example.gg$Row, levels = sort(unique(example.gg$Row)))
png.img <- readPNG(getURLContent("https://i.imgur.com/QeSO7d3.png"))
img.rg <- rasterGrob(png.img, interpolate=TRUE)
gp <- ggplot(example.gg,
aes(x = Col, y = Row, col = Lum))
annotation_custom(
img.rg,
xmin = -2,
xmax = 27,
ymin = -1,
ymax = 18
)
geom_point(shape = 15)
coord_fixed(clip = "off")
theme_void()
theme(plot.margin = unit(c(3, 2, 5, 2), "lines"))
gp

由
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/427658.html
上一篇:使用多個幾何圖形為facetwrap創建圖例和定義顏色
下一篇:箱線圖問題:函式創建中的平線
