2017-07-27 146 views
0

我正在用一个方面网格构建一个ggplot2图。在我的Y轴上是百分比,我的X轴是浓度(以数字表示)。每个小面具有3组(0,24和48小时)在ggplot2中制作离散x轴的线图

ggplot(data=MasterTable, aes(x=Concentration, y=Percentage, group=Time)) + 
    geom_point() + 
    geom_line() + 
    facet_grid(Chemicals ~ Treatments) 

此产生连续的x轴上。由于数值不均匀分布,我宁愿使用离散轴来更好地显示数据。我跟着following tutorial没有运气。第一个数字正是我想要做的。

我还试图格式化轴:

scale_x_discrete(labels("0", "0.1", "2", "50")) 

和格式化线路:

geom_line(aes(Time)) 

和以下this tutorial

我认为这个问题是x轴上的值是整数而不是字符串。这使默认轴连续。我怎样才能改变这?我相信解决方案很简单,我无法弄清楚。

在此先感谢!

+0

欢迎您!我确实将我的评论转换为答案。 – AK88

回答

1

在此page他们做了以下修改df2$dose<-as.factor(df2$dose)。您可以尝试修改x-axisdf2$Concentration<-as.factor(df2$Concentration)

或像这样:

ggplot(data=MasterTable, aes(x=factor(Concentration), y=Percentage, group=Time)) + 
    geom_point() + 
    geom_line() + 
    facet_grid(Chemicals ~ Treatments) 
+1

谢谢!在这一个上花了几个小时。太简单了! 'MasterTable $ Concentration < - as.factor(MasterTable $ Concentration)' – Marty999