小编Wok*_*kel的帖子

让 facet_grid 中的每个图都有自己的 Y 轴值

目前,我无法根据自己的喜好显示图表 Y 轴。我想要的是每个单独的图显示取决于其自身分数的点宽度。请参阅下图,了解我拥有什么以及我想要什么。

在此处输入图片说明

基本上,我希望每个图都依赖于它自己的索引,即Silhouette、Davies-Bouldin 等。就像第一张图(左边的Carlinski-Harabasz)所显示的那样。

这是迄今为止的数据和代码

algorithms <- as.factor(c(rep("kmeans", 4), rep("pam", 4), rep("cmeans", 4)))
index <- as.factor(c(rep("Silhouette", 12), rep("Carlinski-Harabasz", 12)
, rep("Davies-Bouldin",12)))
score <- c(0.12,0.08,0.07,0.05,0.1,0.07,0.09,0.08,0.13,0.11,0.1,0.1,142,106,84,74,128,
99,91,81,156,123,105,95,2.23,2.31,2.25,2.13,2.55,2.12,2.23,2.08,2.23,2.12,2.17,1.97)
clusters <- as.factor(rep(3:6,9))
indices <- data.frame(algorithms, index, score, clusters)

#Some ggplot code
ggplot(indices, aes(clusters, score)) + 
geom_point(aes(size = score, color = algorithms)) + 
facet_grid(.~index, scales = "free_y") 
#I thought the scales function in facet grid might do the trick...
Run Code Online (Sandbox Code Playgroud)

据我了解,我必须围绕 Y 轴比例进行工作。然而,事实证明这对我来说非常棘手。

更新答案

ggplot(indices, aes(clusters, score)) + 
geom_point(aes(size = score, color = algorithms)) + …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

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

将多个字符列转换为 R 中的 as.Date 和 time

我们有一个任意数据集,称为 df:

enter <- c("2017-01-01", "2018-02-02", "2018-03-03") 
guest <- c("Foxtrot","Uniform","Charlie","Kilo")
disposal <- c("2017-01-05", "2018-02-05", "2018-03-09") 
rating <- c("60","50","50")
date <- c("2017-04-10", "2018-04-15", "2018-04-20")
clock <- c("16:02:00", "17:02:00", "18:02:00")
rolex <- c("20:10:00", "20:49:00", "17:44:00") 
df <- data.frame(enter,guest,disposal,rating,date,clock,rolex, stringsAsFactors = F)
Run Code Online (Sandbox Code Playgroud)

我试图完成的是使用dplyr包将 EnterDisposalDate列从字符更改为日期。因此,我想出了以下内容,只需将其链接在一起:

library(dplyr)
library(chron)
df2 <- df %>% mutate(enter = as.Date(enter, format = "%Y-%m-%d")) 
%>% mutate(disposal = as.Date(disposal, format = "%Y-%m-%d")) 
%>% mutate(date = as.Date(date, format = "%Y-%m-%d"))
Run Code Online (Sandbox Code Playgroud)

我所追求的是:变异函数来摆脱多重链接,即当我们有很多具有暗示日期的任意命名的列时?我想按名称指定列,然后应用 as.Date 函数将它们从字符更改为日期。

针对不同操作的一些不适用于本例的解决方案: …

r date converters

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

标签 统计

r ×2

converters ×1

date ×1

ggplot2 ×1