我有以下数据,我试图将其绘制为堆积区域图表:
week Wildtype ARE
3 3770 3740
4 3910 3920
5 3660 3640
6 3750 3790
7 3940 3930
8 3940 3940
9 3830 3810
10 3710 3720
11 3730 3720
12 357 358
将此代码用于堆积区域图表
library(reshape2)
library(ggplot2)
rm(list=ls())
df <- read.csv("Mo_data/mo_qpcr_data2.csv", comment.char = "#", sep=",")
df_melt <- melt(df, id=c("week"))
p1 <- ggplot() + geom_area(aes(y = value, x = week, fill = variable), data = df_melt)
p1
如何更改绘图以使x轴在时间序列中显示每周而不仅仅是5.0,7.5和10.0?
答案 0 :(得分:0)
我会将其添加到代码
+ scale_x_continuous(breaks= unique(df$week) )
library(reshape2)
library(ggplot2)
rm(list=ls())
df <- read.csv("Mo_data/mo_qpcr_data2.csv", comment.char = "#", sep=",")
df_melt <- melt(df, id=c("week"))
p1 <- ggplot() + geom_area(aes(y = value, x = week, fill = variable), data = df_melt) + scale_x_continuous(breaks= unique(df$week) )
p1
答案 1 :(得分:0)
Ggplot将您的周列视为一个数字(这是正确的,因为它是一个数字),因此您的x轴显示为连续。如果您想将周视为离散值,您可以:
1)将周列更改为字符或因子
df_melt$week <- as.factor(df_melt$week)
df_melt$week <- as.factor(df_melt$week)
2)通过scale_axis_discrete
更多信息here