java矩阵传递给r_将列名作为参数传递给R函数

我有一段代码可以在R中生成一个图形,它可以工作,但是有一个字段名

star_sign

variable_name

而是删除硬编码。

my_graph

{

scale_fac

row_count = nrow(df_name)

#problem line here - star_sign appears twice

df_name % mutate(star_sign = as.numeric(factor(star_sign, levels = my_levels)))

df_name %>%

ggplot(aes_string(x = variable_name)) +

geom_line(aes(y = mean), color = "red") +

geom_line(aes(y = min), color = "blue") +

geom_line(aes(y = max), color = "green") +

geom_col(aes(y = exposure / scale_fac), width = 0.5, fill = "blue") +

scale_y_continuous("Linear Predictor", sec.axis = sec_axis(~ .*scale_fac , name = "Exposure")) +

scale_x_continuous(variable_name, breaks = c(1:row_count), labels = df_name$my_levels) +

theme_bw()

}

df

exposure = c(50, 70, 60, 40, 45, 78, 42, 22, 28, 49, 50, 31),

mean = c(1.1, 1.2, 1.4, 1.3, 1.8, 1.6, 1.4, 1.3, 1.2, 1.1, 1.5, 1.3))

df$min

df$max

df$my_levels = c("Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces")

my_graph(df, "star_sign")

硬编码在这一行

df_name % mutate(star_sign = as.numeric(factor(star_sign, levels = my_levels)))

谢谢您。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值