1

我试图通过简单地从 R 翻译工作示例来使 ggplot 在 Python (iPython) 中工作。但是,我收到了很多警告/错误。经过一番摆弄,我得到了图表,但它与用 R 制作的完全不同。这是 R 代码:

require(ggplot2)

example = read.table('exampleData.txt', header=TRUE, sep='\t')

ggplot(data=example, aes(x=case, y=H, fill=factor(type))) +
    geom_bar(position=position_dodge(.9), width=0.5, 
        binwidth=0.5, stat='identity') +
    scale_x_discrete('Case') +
    scale_y_continuous('H')

这产生了很好的数字:

R中的ggplot图

但是,我不能在 Python 中得到相同的结果。在太多错误消息之后,我产生了与上图完全不同的东西。这是Python代码:

from itertools import izip, chain, product
import pandas as pd
import numpy as np
from ggplot import *

example = pd.DataFrame(np.genfromtxt('exampleData.txt', names=True, dtype=None))

print ggplot(aes(x='case', y='H', fill='factor(type)'), data=example) +\
    geom_bar()

拜托,你能帮我解决这个问题吗?另外,在 Python 中绘图有什么全面的吗?此外,R 和 Python 中 ggplot 的一些比较方法?

4

0 回答 0