Actually, a comma should be placed before and after if the abbreviation is not parenthesized. The same is true for i.e. (the other commonly used Latin abbreviation). See below:
Soups often contain a variety of vegetables, e.g., carrots, peas, celery, corn, and squash.
My favorite soup has many vegetables, i.e., vegetable soup.
The same sentences can be written with the abbreviations in parentheses, where the comma is still required "after" the abbreviation but should not be placed "before" (in American English anyway). See again below:
Soups often contain a variety of vegetables (e.g., carrots, peas, celery, corn, and squash).
My favorite soup has many vegetables (i.e., vegetable soup).
Either method is grammatically correct, at least according to American English standards, and choosing to eliminate the parentheses has become quite common (and is perfectly acceptable) in most forms of writing.
However, as others noted, many style guides for formal writing, including APA (which was not previously mentioned) mandate the parenthetical use of these and most other Latin abbreviations within text. The one common exception is use of "et al.," which can be used within or without parentheses in text and reference sections. I don't understand the rationale; since the abbreviations and the parentheses both denote examples or additional explanation provided, use of both seems redundant. Nonetheless, if you're writing for academic or scientific purposes, you will most likely be at the mercy of a style-guide enforcer, so it is best to comply.