我正在尝试使用填充渐变来绘制信号幅度的差异,以描绘头部地图中不同位置的幅度变化。原始代码取自这个关于ERP可视化的精彩site。
我遇到的问题是,虽然颜色渐变在scale_fill_gradientn()中定义,并且它应该取决于幅度值,但程序忽略它并返回黑白图。注意,轮廓也取决于振幅。唯一缺少的是颜色。我试过改变限制和jet.colors的数量,但我得到的数字仍然是黑色和白色。我还检查了颜色功能是否正常,并使用其他类型的图形进行测试,颜色在那里工作正常。
我的猜测是,我的数据中的振幅值可以做些什么。如果它有用,我的振幅列是一组836(唯一)连续值,范围从-24.57到40.57。
提前致谢!
myPlot <- ggplot(interpTopo,
aes(x = x, y = y, fill = amplitude)
) +
geom_raster() +
stat_contour(aes(z = amplitude),
colour = "black",
binwidth = 0.5) +
theme_topo()+
scale_fill_gradientn(colours = jet.colors(10),
limits = c(-45,45),
guide = "colourbar",
oob = squish) +
geom_path(data = maskRing,
aes(x, y, z = NULL, fill =NULL),
colour = "white",
size = 6)+
geom_point(data = myData,
aes(x, y),
size = 1)+
geom_path(data = headShape,
aes(x, y, z = NULL, fill = NULL),
size = 1.5)+
geom_path(data = nose,
aes(x, y, z = NULL, fill = NULL),
size = 1.5)+
coord_equal()
myPlot
修改
我在参与者之间平均了我的数据,因此显着减少了数据框的大小,使其更易于管理。 数据帧interptopo用于幅度值的内插。这是一个示例:
head(interpTopo)
x y amplitude incircle
0.12925576 -0.6829972 -8.718801 TRUE
-0.09694182 -0.6829972 -8.916679 TRUE
-0.06462788 -0.6829972 -9.060801 TRUE
-0.03231394 -0.6829972 -9.155282 TRUE
0.00000000 -0.6829972 -9.205160 TRUE
0.03231394 -0.6829972 -9.215858 TRUE
数据框myData包含几列原始数据(条件(A或B),电极(19个不同电极)和信号幅度)加上几列用于绘制目标
Condition electrode amplitude chanNo theta radius radianTheta
A Fp1 -0.37446309 1 -17.926 0.51499 -0.3128677
B Fp1 -2.31090745 1 -17.926 0.51499 -0.3128677
A Fp2 -1.90578364 34 17.926 0.51499 0.3128677
B Fp2 -0.02573764 34 17.926 0.51499 0.3128677
A F7 -0.16760282 7 -53.913 0.52808 -0.9409594
B F7 -0.25097400 7 -53.913 0.52808 -0.9409594
A F3 -0.45598300 5 -39.947 0.34459 -0.6972067
B F3 -0.57930200 5 -39.947 0.34459 -0.6972067
A F4 -0.25086682 40 39.897 0.34450 0.6963340
B F4 -0.59217445 40 39.897 0.34450 0.6963340
A F8 -0.26977155 42 53.867 0.52807 0.9401565
B F8 -0.39654918 42 53.867 0.52807 0.9401565
A T7 0.85764773 15 -90.000 0.53318 -1.5707963
B T7 1.08665791 15 -90.000 0.53318 -1.5707963
A C3 0.97039173 13 -90.000 0.26669 -1.5707963
B C3 1.65981436 13 -90.000 0.26669 -1.5707963
A C4 1.02980173 50 90.000 0.26667 1.5707963
B C4 1.43448673 50 90.000 0.26667 1.5707963
A T8 -1.06197918 52 90.000 0.53318 1.5707963
B T8 -0.48770773 52 90.000 0.53318 1.5707963
A P7 0.19354909 23 -126.090 0.52808 -2.2006857
B P7 5.44480127 23 -126.090 0.52808 -2.2006857
A P3 1.45094764 21 -140.050 0.34459 -2.4443336
B P3 4.44669364 21 -140.050 0.34459 -2.4443336
A Pz 0.33693382 31 180.000 0.25338 3.1415927
B Pz 1.24227400 31 180.000 0.25338 3.1415927
A P4 1.43877264 58 140.100 0.34450 2.4452063
B P4 3.68937236 58 140.100 0.34450 2.4452063
A P8 0.39259664 60 126.130 0.52807 2.2013838
B P8 4.37601391 60 126.130 0.52807 2.2013838
A O1 -1.44583073 27 -162.070 0.51499 -2.8286551
B O1 3.24404509 27 -162.070 0.51499 -2.8286551
A O2 -2.35238736 64 162.070 0.51499 2.8286551
B O2 2.29718891 64 162.070 0.51499 2.8286551
A Fz 0.13803991 38 0.000 0.25338 0.0000000
B Fz 0.02463536 38 0.000 0.25338 0.0000000
A Cz 0.48804100 48 0.000 0.00000 0.0000000
B Cz 1.60909164 48 0.000 0.00000 0.0000000
x y
-1.585080e-01 4.899897e-01
-1.585080e-01 4.899897e-01
1.585080e-01 4.899897e-01
1.585080e-01 4.899897e-01
-4.267539e-01 3.110460e-01
-4.267539e-01 3.110460e-01
-2.212539e-01 2.641760e-01
-2.212539e-01 2.641760e-01
2.209656e-01 2.643000e-01
2.209656e-01 2.643000e-01
4.264959e-01 3.113826e-01
4.264959e-01 3.113826e-01
-5.331800e-01 3.264678e-17
-5.331800e-01 3.264678e-17
-2.666900e-01 1.632951e-17
-2.666900e-01 1.632951e-17
2.666700e-01 1.632829e-17
2.666700e-01 1.632829e-17
5.331800e-01 3.264678e-17
5.331800e-01 3.264678e-17
-4.267376e-01 -3.110683e-01
-4.267376e-01 -3.110683e-01
-2.212677e-01 -2.641644e-01
-2.212677e-01 -2.641644e-01
3.102908e-17 -2.533800e-01
3.102908e-17 -2.533800e-01
2.209794e-01 -2.642884e-01
2.209794e-01 -2.642884e-01
4.265122e-01 -3.113603e-01
4.265122e-01 -3.113603e-01
-1.585422e-01 -4.899787e-01
-1.585422e-01 -4.899787e-01
1.585422e-01 -4.899787e-01
1.585422e-01 -4.899787e-01
0.000000e+00 2.533800e-01
0.000000e+00 2.533800e-01
0.000000e+00 0.000000e+00
0.000000e+00 0.000000e+00