R 如何在x轴上拆分字符并为其指定颜色
我是R和ggplot2的新手。目前我有这样一个情节: 我想要这样的东西: 不幸的是,我不知道如何在x轴上分割字符并为它们指定不同的颜色 这是我的代码:R 如何在x轴上拆分字符并为其指定颜色,r,ggplot2,split,R,Ggplot2,Split,我是R和ggplot2的新手。目前我有这样一个情节: 我想要这样的东西: 不幸的是,我不知道如何在x轴上分割字符并为它们指定不同的颜色 这是我的代码: attach(trustData) ag <- aggregate(trustData, by = list(type = face_category_and_gender2_ZAUFANIE), mean) plot <- ggplot(data = ag, aes(x = type, y = response)) + li
attach(trustData)
ag <- aggregate(trustData, by = list(type = face_category_and_gender2_ZAUFANIE), mean)
plot <- ggplot(data = ag, aes(x = type, y = response)) + list(geom_point(colour = 'red'))
plot
附加(信任数据)
ag我们可以分离类型列,然后进行绘图
library(dplyr)
library(tidyr)
library(ggplot2)
ag %>%
separate(type, into = c("val", "Type"), "(?=[A-Z])", remove = FALSE) %>%
mutate(val = factor(val, levels = sort(unique(as.numeric(val)))),
Type = factor(Type, levels =c("M", "K"), labels = c("Men", "Woman"))) %>%
ggplot(., aes(x = val, y = response, col = Type)) +
geom_point()
或者在dplyr
ag %>%
separate(type, into = c("val", "Type"), "(?=[A-Z])", remove = FALSE) %>%
mutate(val = factor(val, levels = sort(unique(as.numeric(val)))),
Type = case_when(.$Type == "M" ~ "Men", TRUE ~ "Woman")) %>%
ggplot(., aes(x = val, y = response, col = Type)) +
geom_point()
数据
ag我们可以分离
类型列,然后进行绘图
library(dplyr)
library(tidyr)
library(ggplot2)
ag %>%
separate(type, into = c("val", "Type"), "(?=[A-Z])", remove = FALSE) %>%
mutate(val = factor(val, levels = sort(unique(as.numeric(val)))),
Type = factor(Type, levels =c("M", "K"), labels = c("Men", "Woman"))) %>%
ggplot(., aes(x = val, y = response, col = Type)) +
geom_point()
或者在dplyr
ag %>%
separate(type, into = c("val", "Type"), "(?=[A-Z])", remove = FALSE) %>%
mutate(val = factor(val, levels = sort(unique(as.numeric(val)))),
Type = case_when(.$Type == "M" ~ "Men", TRUE ~ "Woman")) %>%
ggplot(., aes(x = val, y = response, col = Type)) +
geom_point()
数据
ag请显示一个小的可复制示例数据。您必须创建一个组列才能获得该值。如果你展示一些示例数据,我们将更容易帮助你,我将更新。K-Woman M-Ment您展示的图像,是ag
数据还是原始的“trustData”?欢迎来到StackOverflow!请阅读相关信息以及如何给出建议。这将使其他人更容易帮助你。请展示一个小的可复制的示例数据。您必须创建一个组列才能获得该值。如果你展示一些示例数据,我们将更容易帮助你,我将更新。K-Woman M-Ment您展示的图像,是ag
数据还是原始的“trustData”?欢迎来到StackOverflow!请阅读相关信息以及如何给出建议。这将使其他人更容易帮助你。