Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R ggplot具有多个刻度的输出_R_Ggplot2_Data Visualization - Fatal编程技术网

R ggplot具有多个刻度的输出

R ggplot具有多个刻度的输出,r,ggplot2,data-visualization,R,Ggplot2,Data Visualization,我有一个不同类型的数据(“数字”或“货币”),需要在图形中融化和输出。我不知道如何适应多个刻度。以下是问题的一个例子: library(scales); library(melt) # Generate some random V1 <- 1:20 V2 <- sample(1:100, 10, replace = F) V3 <- sample(1: 100, 10, replace = F) V3 <- dollar(V3) # Melt data data &

我有一个不同类型的数据(“数字”或“货币”),需要在图形中融化和输出。我不知道如何适应多个刻度。以下是问题的一个例子:

library(scales); library(melt)

# Generate some random 
V1 <- 1:20
V2 <- sample(1:100, 10, replace = F)
V3 <- sample(1: 100, 10, replace = F)
V3 <- dollar(V3)

# Melt data
data <- data.frame(V1 = V1, V2 = V2, V3 = V3)
data_melt <- melt(data, id.vars = c("V1"))


# Now I want to plot this data with different scales
ggplot(data_melt, aes(x = V1, y = value , col = variable)) + 
    geom_point()
library(scales);图书馆(melt)
#生成一些随机变量

V1
scales::dollar
V3
转换为字符串,字符串将
数据转换为字符串。frame
然后转换为因数,因数将
重塑2::melt
V2
合并,将
V2
从整数转换为字符串。这些都不是你想要的

相反,将数据作为数字保存到ggplot内部,在ggplot内部,您可以将适当的
缩放
函数传递到
缩放连续
,例如

库(tidyverse)
种子(47)

df_wide AFAIK没有名为
melt
的包。在
restrape2
data中有
melt
函数。表
,如果您是指其中一个,或
tidyr::gather
utils::stack
stats::restrape
是相关的。另外,您当前的代码是如何失败的或没有提供您想要的东西的?