【发布时间】:2017-05-30 18:43:36
【问题描述】:
紧迫的最后期限意味着我已经没有时间来解决这个问题了,如果之前有人问过,我深表歉意。
我不知道如何(或者如果可能的话)将稍微扩展的 RColorBrewer 调色板应用到 ggplot 线图中的因子数据。
我有以下 3 个变量数据(很多数据点,所以我不会在这里全部粘贴),在一个已经融化的数据框中。
> head(spec.melt)
Temperature Wavelength CD_Intensity
1 20 260 0.0807910
2 25 260 0.3019320
3 30 260 0.1363325
4 35 260 0.0000000
5 40 260 0.1354045
6 45 260 0.0000000
... # tail(spec.melt)
Temperature Wavelength CD_Intensity
5635 65 185 0.2499200
5636 70 185 2.5051893
5637 75 185 0.4399785
5638 80 185 4.4368350
5639 85 185 2.0015100
5640 90 185 2.8696540
对于每个温度 (25-90),进行波长扫描 (260nm-190nm),收集 CD 强度,因此有 15 个 260-190nm 测量的光谱折叠在这个 df 中。
到目前为止,我可以很好地绘制这个,并且应用了默认的 ggplot 主题。由于系列数据将是温度,我想使用显示这一点的主题(例如 RColorBrewers "RdYlBu")为它们着色。
我有 15 个温度,默认情况下“RdYlBu”是 11 个色谱。
这是我的代码:
# Import spectrum data
spectrum.obj <- read.table(spectrum,
sep = ",",
header = TRUE,
row.names = 1,
check.names = FALSE)
spec.melt <- melt(t(spectrum.obj), value.name = "CD_Intensity", varnames=c("Temperature","Wavelength"))
# # Plot and customise spectrum space
spectrum.img <- ggplot(spec.melt, aes(x=Wavelength, y=CD_Intensity, group=factor(Temperature)))
spectrum.img <- spectrum.img + geom_line(aes(color=factor(Temperature)))
# Axis titles
spectrum.img <- spectrum.img + ylab("CD Intensity (mdeg)") +
xlab("Wavelength (nm)") +
guide_legend(title="my awesome title")
# Make transparent
spectrum.img <- spectrum.img + theme_bw()
spectrum.img <- spectrum.img + theme(legend.position = "bottom",
legend.title = element_text("test"),
plot.background = element_blank(),
panel.background = element_blank(),
legend.background = element_blank())
spectrum.img
目前,如果我将 geom_line(aes(color=factor(Temperature))) 更改为其他任何内容,它就会中断。
对于奖励积分,如果有人能告诉我为什么 legend.title 没有产生任何很棒的东西,目前,我被“因素(温度)”所困扰
编辑: 这是原始数据(CSV 格式) https://pastebin.com/ZwtvU8Kq
【问题讨论】: