如何在一张图中制作不同实验的散点图以进行比较,并使用 R 包含所有最佳拟合线
How to make a scatter plot with different experiments all in one graph for comparison and all lines of best fit are included using R
我尝试创建一个包含四个不同变量的散点图:SMX 与 E.coli、SMX 与 S.aureus、TMP 与 E.coli、TMP 与金黄色葡萄球菌。我是 R 的初学者。我可以像这样在 Excel 中创建图形:
但我被特别要求在 R studio 中创建图表。我已经花了一个星期的时间来尝试创建这个图表,但它最终还是行不通。有人可以帮我看图表吗?谢谢。
R中的数据集:
dput(Bacteria)
structure(list(`Log [antibiotic concentration] (log(µg/µl))` = c(0,
0.301029996, 0.602059991, 0.77815125, 0.903089987, 1, 0, -0.698970004,
-0.397940009, -0.22184875, -0.096910013, 0, 0, -1, -0.698970004,
-0.522878745, -0.397940009, -0.301029996, 0, 0, 0.301029996,
0.477121255, 0.602059991, 0.698970004), `Mean Absorbance` = c(0.3925,
0.375, 0.388, 0.358, 0.357, 0.4115, 0.3465, 0.299, 0.2805, 0.2895,
0.3495, 0.4585, 0.3975, 0.405, 0.404, 0.404, 0.4105, 0.474, 0.3975,
0.405, 0.404, 0.404, 0.4105, 0.474), Experiment = c("SMX with E. coli",
"SMX with E. coli", "SMX with E. coli", "SMX with E. coli", "SMX with E. coli",
"SMX with E. coli", "SMx with S. aureus", "SMx with S. aureus",
"SMx with S. aureus", "SMx with S. aureus", "SMx with S. aureus",
"SMx with S. aureus", "TMP with E . coli", "TMP with E . coli",
"TMP with E . coli", "TMP with E . coli", "TMP with E . coli",
"TMP with E . coli", "TMP with S. aureus", "TMP with S. aureus",
"TMP with S. aureus", "TMP with S. aureus", "TMP with S. aureus",
"TMP with S. aureus")), .Names = c("Log [antibiotic concentration] (log(µg/µl))",
"Mean Absorbance", "Experiment"), row.names = c(NA, -24L), class = c("tbl_df",
"tbl", "data.frame"))
非常适合 ggplot2。将数据保存在 d
中并将第一列重命名为 "Log"
.
library(ggplot2)
ggplot(d, aes(Log, `Mean Absorbance`, color=Experiment)) +
geom_point() +
geom_smooth(method = "lm", se = F) +
xlab("Log [antibiotic concentration] (log(µg/µl))") +
theme(legend.position = "bottom")
我尝试创建一个包含四个不同变量的散点图:SMX 与 E.coli、SMX 与 S.aureus、TMP 与 E.coli、TMP 与金黄色葡萄球菌。我是 R 的初学者。我可以像这样在 Excel 中创建图形:
但我被特别要求在 R studio 中创建图表。我已经花了一个星期的时间来尝试创建这个图表,但它最终还是行不通。有人可以帮我看图表吗?谢谢。
R中的数据集:
dput(Bacteria)
structure(list(`Log [antibiotic concentration] (log(µg/µl))` = c(0,
0.301029996, 0.602059991, 0.77815125, 0.903089987, 1, 0, -0.698970004,
-0.397940009, -0.22184875, -0.096910013, 0, 0, -1, -0.698970004,
-0.522878745, -0.397940009, -0.301029996, 0, 0, 0.301029996,
0.477121255, 0.602059991, 0.698970004), `Mean Absorbance` = c(0.3925,
0.375, 0.388, 0.358, 0.357, 0.4115, 0.3465, 0.299, 0.2805, 0.2895,
0.3495, 0.4585, 0.3975, 0.405, 0.404, 0.404, 0.4105, 0.474, 0.3975,
0.405, 0.404, 0.404, 0.4105, 0.474), Experiment = c("SMX with E. coli",
"SMX with E. coli", "SMX with E. coli", "SMX with E. coli", "SMX with E. coli",
"SMX with E. coli", "SMx with S. aureus", "SMx with S. aureus",
"SMx with S. aureus", "SMx with S. aureus", "SMx with S. aureus",
"SMx with S. aureus", "TMP with E . coli", "TMP with E . coli",
"TMP with E . coli", "TMP with E . coli", "TMP with E . coli",
"TMP with E . coli", "TMP with S. aureus", "TMP with S. aureus",
"TMP with S. aureus", "TMP with S. aureus", "TMP with S. aureus",
"TMP with S. aureus")), .Names = c("Log [antibiotic concentration] (log(µg/µl))",
"Mean Absorbance", "Experiment"), row.names = c(NA, -24L), class = c("tbl_df",
"tbl", "data.frame"))
非常适合 ggplot2。将数据保存在 d
中并将第一列重命名为 "Log"
.
library(ggplot2)
ggplot(d, aes(Log, `Mean Absorbance`, color=Experiment)) +
geom_point() +
geom_smooth(method = "lm", se = F) +
xlab("Log [antibiotic concentration] (log(µg/µl))") +
theme(legend.position = "bottom")