小编Amm*_*ema的帖子

使用 ggplot2 为组自定义颜色

我正在尝试使用下面给出的代码使用 ggplot2 绘制线性判别图:

require(MASS) 
require(ggplot2) 
data("iris")
my.data <- iris
model <- lda(formula = Species ~ ., data = my.data)
data.lda.values <- predict(model)
plot.data <- data.frame(X=data.lda.values$x[,1], Y=data.lda.values$x[,2], Species=my.data$Species)
p <- ggplot(data=plot.data, aes(x=X, y=Y)) +
geom_point(aes(color=Species)) +
theme_bw()
p
Run Code Online (Sandbox Code Playgroud)

此代码给出了 lda 图,如下所示, 在此输入图像描述

但我想更改三个群体的颜色,我已修改了上述代码,如下所示,

my_colors <- c("yellow","magenta","cyan")
p <- ggplot(data=plot.data, aes(x=X, y=Y,color=my_colors)) +
geom_point() +
scale_fill_manual(values=my_colors) 
p
Run Code Online (Sandbox Code Playgroud)

但此代码给出错误Aesthetics must be either length 1 or the same as the data (150): x, y, color。有什么办法可以实现这个目标吗?

r ggplot2

10
推荐指数
1
解决办法
1万
查看次数

在同一循环中使用列表填充dict

我正在尝试用pandas sereis中的列式字符出现来填充一个字典.sereis如下:

>>> jkl
1     ATGC
2     GTCA    
3     CATG
Name: 0, dtype: object
Run Code Online (Sandbox Code Playgroud)

我希望dict的方式包含所有字符作为键和列的明确出现频率列表作为dict的值,如下所示:

{'A':[1,1,0,1],'C':[1,0,1,1],'G':[1,0,1,1],'T':[0,2,1,0]}
Run Code Online (Sandbox Code Playgroud)

我尝试了几个代码,这是其中之一:

mylist = ['A', 'C', 'G','T']
dict = {key: None for key in mylist}
for i,(a,b) in enumerate(zip_longest(jkl[1],dict.keys())):
    t=str(list(jkl.str[i]))
    single_occurrences = Counter(t)    
    kl.append(single_occurrences.get(b))
    dict[b]=kl
Run Code Online (Sandbox Code Playgroud)

但这个字典不包含所需的输出,是否有解决方案?

python dictionary python-3.x pandas

3
推荐指数
1
解决办法
82
查看次数

获取匹配括号的索引

嗨,我正在尝试打印以下括号模式的索引:

((((((...)))(((...))))))
Run Code Online (Sandbox Code Playgroud)

如下:

0 23
1 22
2 21
3 11
4 10
5 9
12 20
13 19
14 18
Run Code Online (Sandbox Code Playgroud)

我尝试使用下面给出的此perl代码来实现此目的:

#!/usr/bin/perl
use strict;
use warnings;

my $string = '((((((...)))(((...))))))';
my @myarray = split('', $string); 
my @stack;
my @stack1;



while (my ($index, $element) = each(@myarray))
{

   if ($element eq '(')
   {
   push(@stack, $index);  
   }

   if ($element eq ')')
   {
   push(@stack1, $index);  
   }  
}


print "$stack[$_]-$stack1[$_]\n" for (0 .. $#stack);
Run Code Online (Sandbox Code Playgroud)

但是上面的代码给了我以下输出,这不是必需的输出:

0-9
1-10
2-11
3-18
4-19
5-20
12-21
13-22
14-23 …
Run Code Online (Sandbox Code Playgroud)

arrays perl parentheses

3
推荐指数
1
解决办法
59
查看次数

标签 统计

arrays ×1

dictionary ×1

ggplot2 ×1

pandas ×1

parentheses ×1

perl ×1

python ×1

python-3.x ×1

r ×1