我想根据大于数据范围的中断范围绘制具有颜色的等高线填充,以便不同的绘图具有相同的比例。在下面的示例中,蓝色和红色分别对应于更多的负值或正值。但是,当绘图不包含全范围时,geom_contour_filled会识别断点,但与色标不匹配。所以,正值都是蓝色的。 library(ggplot2)
grid <- expand.grid(x=0:10,y=0:10)
grid$z <- with(grid, x*y) # 0 to 100 does not work as expected
# grid$z <- with(grid, 2*x*y-100) # -100 to 1
我目前正在尝试处理语音信号。我已经在-1和1之间缩放了一个向量。我已经设法做到了,但请看我获得的向量的图表。我需要该信号以0为中心,以便获得将被提供给神经网络的特征向量。它略低于0。
如何在-1和1之间缩放此向量,并将中心保持在0?
原始信号:
缩放信号:
代码和和归一化函数:
samplerate, data = wavfile.read('avarii.wav')
times = np.arange(len(data))/float(samplerate)
print(times)
print(len(data))
print(samplerate)
# Make the
在ggplot中设置地图的色标有困难。我需要灰度图像。非常感谢你给我出了个错误的主意。我还想知道是否有一种更有效的方法将颜色变量放入ggplot (即,比将其附加到‘加强’数据)?
library(ggplot2)
states <- map_data("state")
var <- data.frame(table(states$region)) # using rows as a dummy variable
states$variable <- var$Freq[match(states$region,var$Var1)]
map <- ggpl
我想给一个特定的分类变量添加颜色。例如,我想特别强调(通过添加颜色)刚毛物种;对于其他物种(如处女色和云芝色),只突出黑点。我想应该有个简单的方法。我对R很陌生。
data(iris)
library(ggplot2)
#This is not desirable
ggplot(iris, aes(Sepal.Length, Petal.Width)) + geom_point() + geom_point(aes(colour=Species))
#This is what I aim to achieve, but it is not working
ggplot(iris, aes(Se
对于ggplot2,是否有一种方法可以指定相对于绘图面板大小的色条宽度?
也就是说,什么可以提供给legend.key.width,使键的相对宽度保持不变,而不管情节的大小如何?
ggplot(mpg) +
geom_point(aes(cty, hwy, color = year)) +
theme(legend.position = "bottom",
legend.key.width = unit(0.1, "npc")) # not relative
# or could it be done with a custom the