Tarmogoyf's power is equal to the number of card types among cards in all graveyards and its toughness is equal to that number plus 1.
The ability that defines Tarmogoyf’s power and toughness works in all zones, not just the battlefield. If Tarmogoyf is in your graveyard, it will count itself.
Tarmogoyf counts card types, not cards. If the only card in all graveyards is a single artifact creature, Tarmogoyf will be 2/3. If the only cards in all graveyards are ten artifact creatures, Tarmogoyf will still be 2/3.
The card types that can appear on cards in a graveyard are artifact, creature, enchantment, instant, land, planeswalker, sorcery, and tribal. Legendary, basic, and snow are supertypes, not card types.
If an instant or sorcery spell deals damage to Tarmogoyf or lowers its toughness, that spell is put into its owner’s graveyard before state-based actions are performed. If that spell is the first of its type to enter a graveyard, it will raise Tarmogoyf’s toughness before the game checks to see if Tarmogoyf dies.