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)
#生成一些随机变量
V1scales::dollar
将V3
转换为字符串,字符串将数据转换为字符串。frame
然后转换为因数,因数将重塑2::melt
与V2
合并,将V2
从整数转换为字符串。这些都不是你想要的
相反,将数据作为数字保存到ggplot内部,在ggplot内部,您可以将适当的缩放
函数传递到缩放连续
,例如
库(tidyverse)
种子(47)
df_wide AFAIK没有名为melt
的包。在restrape2
和data中有melt
函数。表
,如果您是指其中一个,或tidyr::gather
,utils::stack
和stats::restrape
是相关的。另外,您当前的代码是如何失败的或没有提供您想要的东西的?