这是我正在使用的代码:
library(ggplot2)
coco1<-rnorm(10000,0,1)
coco2<-rnorm(10000,10,5)
coco3<-rnorm(10000,20,10)
coco4<-rnorm(10000,30,20)
decile<-rbinom(10000,3,1/2)+1
coconut<-data.frame(coco1,coco2,coco3,coco4,decile)
p <- ggplot(coconut, aes(factor(decile), coco1))
p <- p + geom_violin(aes(colour = "1"), alpha = .5, size=2)
q <- p + geom_violin(aes(y = coco2, colour = "2"), alpha = .5, size=2)
q <- q + geom_violin(aes(y = coco3, colour = "3"), alpha = .5, size=2)
q <- q + geom_violin(aes(y = coco4, colour = "4"), alpha = .5, size=2)
q
Run Code Online (Sandbox Code Playgroud)
生成此图像:
请注意小提琴的主体如何在您走得越远的小提琴层中产生透明度问题?理想情况下,我希望身体的 alpha=0 和身体的轮廓有 alpha=1。
在ggplot我有一个图表,其 x 轴标签超出了 RStudio 中的绘图窗口,即使我尝试导出图片并且无论我制作图片有多宽。以下是我当前使用limitsin 的解决方案scale_x_continuous。是否可以延长图片以便我可以捕获我的最后一个 x 轴标签(即 25021643)但不延长线段?
上面复制的代码:
library(ggplot2)
p <-
ggplot(NULL) +
xlab("x-axis") +
theme_bw() +
scale_x_continuous(breaks = as.integer(seq(0,25021643,(25021643/4))), limits=c(0,26021643),labels = as.integer(seq(0,25021643,(25021643/4))), expand = c(0,0)) +
scale_y_continuous(limits = c(-1, (nrow(chr5)+1)), expand = c(0,0)) +
geom_hline(yintercept = -1) +
geom_segment(aes(x = 0, y = -1, xend = 0, yend = -0.9)) +
geom_segment(aes(x = 25021643, y = -1, xend = 25021643, yend = -0.9)) +
theme(panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
panel.border=element_blank(),
axis.ticks.y = element_blank(),
axis.title.y …Run Code Online (Sandbox Code Playgroud) 我有一个用Julia编写的非常简单的函数,需要运行数百万次.
码:
function randfunc()
#rands could be a global variable if desired
rands = rand(200,100000)
for i=1:100000
#the alphabet can continue (and in Q1 as well)
# rand(1:100000) generates a random number within the number of columns in rands
a = rand(1:100000)
b = rand(1:100000)
c = rand(1:100000)
d = rand(1:100000)
e = rand(1:100000)
Q1 = hcat(rands[:,a],rands[:,b],rands[:,c],rands[:,d],rands[:,e])
Q2 = *(Q1.',Q1)
end
end
Run Code Online (Sandbox Code Playgroud)
有没有办法加快hcat功能或用更高效的东西取而代之?
加速这个功能的另一种方法是手动进行矩阵乘法而不构造Q1矩阵,但是内置*(,)算子运行速度比使用+'s和*'s 更快,至少在我的尝试中,这样做似乎有更多开销不仅仅是构建Q1.
使用rands = convert(Array{Float32}, rands)有点帮助,但Float16实际上更糟(特别是对于矩阵乘法).中的元素rands …