小编Lib*_*ici的帖子

在ggplot中使用预定义的调色板

有谁知道如何在ggplot中使用预定义的调色板?

我有一个我想要使用的颜色矢量:

rhg_cols <- c("#771C19", "#AA3929", "#E25033", "#F27314", "#F8A31B", 
              "#E2C59F", "#B6C5CC", "#8E9CA3", "#556670", "#000000")
Run Code Online (Sandbox Code Playgroud)

但是当我试图将它传递给任何事情时

ggplot(mydata, aes(factor(phone_partner_products)), color = rhg_cols) +
  geom_bar()
Run Code Online (Sandbox Code Playgroud)

r ggplot2

33
推荐指数
4
解决办法
4万
查看次数

node-formidable和一个简单的进度条

如果我查看node-formidable文档,我可以阅读:

"Event: 'progress' (bytesReceived, bytesExpected)
Emitted after each incoming chunk of data that has been parsed. 
Can be used to roll your    own progress bar."
Run Code Online (Sandbox Code Playgroud)

我想知道如何实现我自己的进度条我的意思是如何阅读该信息客户端?我很困惑.它是通过在POST开始后启动的轮询GET实现的,还是可以在上传时从POST请求中读取信息?

如果我看看这个:

http.createServer(function(req, res) {
  if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
    // parse a file upload
    var form = new formidable.IncomingForm();
    form.parse(req, function(err, fields, files) {
      res.writeHead(200, {'content-type': 'text/plain'});
      res.write('received upload:\n\n');
      res.end(sys.inspect({fields: fields, files: files}));
    });
    return;
  }
Run Code Online (Sandbox Code Playgroud)

看起来/ upload url正在处理POST请求并返回一些res.write('收到上传:\n \n');

我的问题是谁可以阅读

res.write('received upload:\n\n');
Run Code Online (Sandbox Code Playgroud)

node.js

6
推荐指数
2
解决办法
8102
查看次数

在R图中标注百分比

嗨,我已经制作了这个功能,需要一张桌子并为条形图准备标签

prepare_labels <- function(ft){
  labs <- ft
  labs <- paste(labs, "\n", sep="")
  labs <- paste(labs, round(prop.table(ft)*100,2), sep="")
  labs <- paste(labs, "%", sep="")
  return(labs)
}
Run Code Online (Sandbox Code Playgroud)

它实际上工作正常,但有没有更好的方法来编写该功能,上面的代码看起来很丑,我想编写漂亮的代码:-)

例如:

ft <- table(mydata$phone_partner_products)
prepare_labels(ft)
[1] "3752\n34.09%" "226\n2.05%"   "2907\n26.41%" "1404\n12.76%" "1653\n15.02%"
[6] "1065\n9.68%" 
Run Code Online (Sandbox Code Playgroud)

r

4
推荐指数
2
解决办法
3656
查看次数

使用R中的变量定义$ right参数

我想将一个变量传递给二元运算符$.

假设我有这个

> levels(diamonds$cut)
[1] "Fair"      "Good"      "Very Good" "Premium"   "Ideal" 
Run Code Online (Sandbox Code Playgroud)

然后我想创建一个函数,将$的选择器作为参数

my_helper <- function (my_param) {
  levels(diamonds$my_param)
}
Run Code Online (Sandbox Code Playgroud)

但这不起作用

> my_helper(cut)
NULL

> my_helper("cut")
NULL
Run Code Online (Sandbox Code Playgroud)

r

4
推荐指数
1
解决办法
596
查看次数

标签 统计

r ×3

ggplot2 ×1

node.js ×1