R:列标题为ylim,行名称为xlim(在R中)
我的数据如下:R:列标题为ylim,行名称为xlim(在R中),r,plot,visualization,analysis,R,Plot,Visualization,Analysis,我的数据如下: Date Medicine1 Medicine2 Medicine3 Medicine4 2014-01-01 0.986 0.897 0.765 0.566 2014-02-01 0.989 0.888 0.778 0.587 2014-03-01 0.991 0.867 0.788
Date Medicine1 Medicine2 Medicine3 Medicine4
2014-01-01 0.986 0.897 0.765 0.566
2014-02-01 0.989 0.888 0.778 0.587
2014-03-01 0.991 0.867 0.788 0.565
2014-04-01 0.982 0.883 0.771 0.532
2014-05-01 0.995 0.873 0.799 0.588
我正在使用matplot()函数来绘制上述数据。以下是我的代码:
med_temp = as.matrix(Medicine[,2:(length(Medicine[1,]))])
matplot(med_temp, type = c("b"), pch = 1, col = 2:(length(Medicine[1,])))
图为:
我希望列标题为ylim,日期列为xlim。我试着用
ylim = as.vector("Medicine1","Medicine2","Medicine3","Medicine4") and
ylim = c("Medicine1","Medicine2","Medicine3","Medicine4")
这两个都给了我错误。我该怎么做才能得到我想要的格式?有办法吗
提前谢谢你的帮助
实际数据:
Month Retention1 Diff
Month1 100.0 0.0
Month2 95.5 -4.5
Month3 90.6 -4.9
Month4 85.9 -4.7
Month5 82.0 -3.9
我认为你在玩弄错误的参数
ylim=
和xlim=
用于控制轴上的值范围,它们与标记轴无关。所以也许你想要像这样的东西
med_temp = as.matrix(Medicine[,2:(length(Medicine[1,]))])
matplot(med_temp, type = c("b"), pch = 1, col = 2:(length(Medicine[1,])), xaxt="n")
axis(1, at=1:nrow(med_temp), labels=Medicine$Date)
axis(4, at=med_temp[nrow(med_temp), ],labels=colnames(med_temp), 4)
我认为您在这里使用了错误的参数
ylim=
和xlim=
用于控制轴上的值范围,它们与标记轴无关。所以也许你想要像这样的东西
med_temp = as.matrix(Medicine[,2:(length(Medicine[1,]))])
matplot(med_temp, type = c("b"), pch = 1, col = 2:(length(Medicine[1,])), xaxt="n")
axis(1, at=1:nrow(med_temp), labels=Medicine$Date)
axis(4, at=med_temp[nrow(med_temp), ],labels=colnames(med_temp), 4)
我认为这里最好使用轴(
axes=F
)进行绘图,并使用text
对绘图进行注释。您还可以使用legend
添加适当的图例
cols <- seq_len(ncol(med_temp))
matplot(med_temp, type = c("b"), pch = 1, col=cols,axes=FALSE)
text(1.5,med_temp[1,],labels = colnames(med_temp),col=cols,srt=10)
axis(1,at=1:5,labels=Medicine$Date)
cols我认为这里最好使用轴(axes=F
)进行绘图,并使用text
对绘图进行注释。您还可以使用legend
添加适当的图例
cols <- seq_len(ncol(med_temp))
matplot(med_temp, type = c("b"), pch = 1, col=cols,axes=FALSE)
text(1.5,med_temp[1,],labels = colnames(med_temp),col=cols,srt=10)
axis(1,at=1:5,labels=Medicine$Date)
cols您也可以使用ggplot进行以下操作:
mm = melt(ddf)
ggplot(mm, aes(x=Date, y=value, group=variable, color=variable))+geom_line()+geom_point()
您也可以使用ggplot进行以下操作:
mm = melt(ddf)
ggplot(mm, aes(x=Date, y=value, group=variable, color=variable))+geom_line()+geom_point()
你的意思是xlab
和ylab
?你的意思是xlab
和ylab
?谢谢Flick先生!!这就是我想要实现的。我可以得到左边的数字,但不能得到右边显示的行的名称。谢谢你的帮助!这是我在这里发布的测试数据。当我应用到实际数据时,会收到一条警告消息:“xant”不是一个图形参数(当我执行第一行和第二行代码时——相当于这里的med_temp和matplot(…)。你知道我为什么会这样吗?谢谢信息是“xant”的?那可能应该是“xaxt”,对吧?警告信息中是“xant”哦,我不知道那是什么意思。除非你能提供重现问题的样本数据,否则我不知道该告诉你什么。我只能帮助我重现错误。试着找出你的真实数据与你发布的数据有什么不同。谢谢Flick先生!!这就是我想要实现的。我可以得到左边的数字,但不能得到右边显示的行的名称。谢谢你的帮助!这是我在这里发布的测试数据。当我应用到实际数据时,会收到一条警告消息:“xant”不是一个图形参数(当我执行第一行和第二行代码时——相当于这里的med_temp和matplot(…)。你知道我为什么会这样吗?谢谢信息是“xant”的?那可能应该是“xaxt”,对吧?警告信息中是“xant”哦,我不知道那是什么意思。除非你能提供重现问题的样本数据,否则我不知道该告诉你什么。我只能帮助我重现错误。尝试找出您的真实数据与您发布的数据有何不同。不要忘记导入restrape2
和ggplot2
。不要忘记导入restrape2
和ggplot2
。